@@ -1084,8 +1084,17 @@ following class definition:
1084
1084
}
1085
1085
----
1086
1086
1087
- When the above POJO is defined as a bean in a Spring IoC container, the bean instance
1088
- can be made transactional by adding merely __one__ line of XML configuration:
1087
+ Used at the class level as above, the annotation indicates a default for all methods
1088
+ of the declaring class (as well as its subclasses). Alternatively, each method can
1089
+ get annotated individually. Note that a class-level annotation does not apply to
1090
+ ancestor classes up the class hierarchy; in such a scenario, methods need to be
1091
+ locally redeclared in order to participate in a subclass-level annotation.
1092
+
1093
+ When a POJO class such as the one above is defined as a bean in a Spring context,
1094
+ you can make the bean instance transactional through an `@EnableTransactionManagement`
1095
+ annotation in a `@Configuration` class. See the javadoc for full details.
1096
+
1097
+ In XML configuration, the `<tx:annotation-driven/>` tag provides similar convenience:
1089
1098
1090
1099
[source,xml,indent=0]
1091
1100
[subs="verbatim,quotes"]
@@ -1109,6 +1118,7 @@ can be made transactional by adding merely __one__ line of XML configuration:
1109
1118
1110
1119
<!-- enable the configuration of transactional behavior based on annotations -->
1111
1120
__<tx:annotation-driven transaction-manager="txManager"/>__<!-- a PlatformTransactionManager is still required -->
1121
+
1112
1122
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
1113
1123
<!-- (this dependency is defined somewhere else) -->
1114
1124
<property name="dataSource" ref="dataSource"/>
@@ -1128,13 +1138,6 @@ dependency-inject has any other name, then you have to use the `transaction-mana
1128
1138
attribute explicitly, as in the preceding example.
1129
1139
====
1130
1140
1131
- [NOTE]
1132
- ====
1133
- The `@EnableTransactionManagement` annotation provides equivalent support if you are
1134
- using Java based configuration. Simply add the annotation to a `@Configuration` class.
1135
- See the javadocs for full details.
1136
- ====
1137
-
1138
1141
.Method visibility and @Transactional
1139
1142
****
1140
1143
When using proxies, you should apply the `@Transactional` annotation only to methods
@@ -1144,20 +1147,20 @@ method does not exhibit the configured transactional settings. Consider the use
1144
1147
AspectJ (see below) if you need to annotate non-public methods.
1145
1148
****
1146
1149
1147
- You can place the `@Transactional` annotation before an interface definition, a method
1150
+ You can apply the `@Transactional` annotation to an interface definition, a method
1148
1151
on an interface, a class definition, or a __public__ method on a class. However, the
1149
1152
mere presence of the `@Transactional` annotation is not enough to activate the
1150
- transactional behavior. The `@Transactional` annotation is simply metadata that can be
1151
- consumed by some runtime infrastructure that is `@Transactional`-aware and that can use
1152
- the metadata to configure the appropriate beans with transactional behavior. In the
1153
- preceding example, the `<tx:annotation-driven/>` element __switches on__ the
1153
+ transactional behavior. The `@Transactional` annotation is simply metadata that can
1154
+ be consumed by some runtime infrastructure that is `@Transactional`-aware and that
1155
+ can use the metadata to configure the appropriate beans with transactional behavior.
1156
+ In the preceding example, the `<tx:annotation-driven/>` element __switches on__ the
1154
1157
transactional behavior.
1155
1158
1156
1159
[TIP]
1157
1160
====
1158
1161
Spring recommends that you only annotate concrete classes (and methods of concrete
1159
- classes) with the `@Transactional` annotation, as opposed to annotating interfaces. You
1160
- certainly can place the `@Transactional` annotation on an interface (or an interface
1162
+ classes) with the `@Transactional` annotation, as opposed to annotating interfaces.
1163
+ You certainly can place the `@Transactional` annotation on an interface (or an interface
1161
1164
method), but this works only as you would expect it to if you are using interface-based
1162
1165
proxies. The fact that Java annotations are __not inherited from interfaces__ means that
1163
1166
if you are using class-based proxies ( `proxy-target-class="true"`) or the weaving-based
@@ -2364,6 +2367,7 @@ class, providing SQL and any necessary parameters. The same is true for the
2364
2367
The `JdbcTemplate` can be used within a DAO implementation through direct instantiation
2365
2368
with a `DataSource` reference, or be configured in a Spring IoC container and given to
2366
2369
DAOs as a bean reference.
2370
+
2367
2371
[NOTE]
2368
2372
====
2369
2373
The `DataSource` should always be configured as a bean in the Spring IoC container. In
@@ -2376,7 +2380,6 @@ corresponding to the fully qualified class name of the template instance (typica
2376
2380
`JdbcTemplate`, but it may be different if you are using a custom subclass of the
2377
2381
`JdbcTemplate` class).
2378
2382
2379
-
2380
2383
[[jdbc-JdbcTemplate-examples]]
2381
2384
===== Examples of JdbcTemplate class usage
2382
2385
0 commit comments