-
Notifications
You must be signed in to change notification settings - Fork 38.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CGLIB proxies should still consider @Transactional annotations on interface methods [SPR-14322] #18894
Comments
Oliver Drotbohm commented Attached a sample using Spring Boot. On 1.3 (with target class proxying disabled by default) the application can be bootstrapped, on 1.4 M3 the bootstrap fails due to the situation described above. Manually enabling target class proxying on 1.3 results in the same problem. Boot can even be moved out of the picture by using this class to bootstrap the app: @Configuration
@ComponentScan
@EnableTransactionManagement(proxyTargetClass = true)
public class TxDifferencesApplication {
@Bean
public DataSourceTransactionManager transactionManager() {
return new DataSourceTransactionManager(dataSource());
}
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL).build();
}
public static void main(String[] args) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(TxDifferencesApplication.class);
}
} |
Oliver Drotbohm commented I just wondered: isn't that a problem with Spring MVC controllers using |
Stéphane Nicoll commented We've enabled CGLIB proxies by default in Boot 1.4 and that broke things for our users, see #6693 |
Harald Radi commented Oliver, it is. I just stumbled upon this issue because of that and due to spring-projects/spring-boot#5423. I don't see any better option than working around the Spring Boot autoconfiguration for now. |
Dave Syer commented I think the tests in #19516 show that this is not a problem for all interceptors (there's an
|
Oliver Drotbohm commented Putting them on the interface makes sense in cases where the implementation doesn't even show up in kind of documentation (e.g. due to the implementation class being held in package scope) and the annotation functionality being a crucial part of the public contract. I'd argue there's value in knowing a method will be executed transactionally if I just study the interface. |
Harald Radi commented In our specific case we dynamically generate client-proxies, hence i definitely need the |
Harald Radi commented
|
Juergen Hoeller commented We're tracking handler method annotations separately in #15682, and we got dedicated tickets for So rest assured, we are revisiting the wider issue, with this ticket as one of four work items. The general target is 5.0 RC1; we're considering backports to the 4.3.x line. |
Harald Radi commented Thanks for the update, and the effort! |
Oliver Drotbohm opened SPR-14322 and commented
If an application components implements an interface whose methods carry annotations that are triggering interceptors (e.g. for transactions), enabling target class proxying will result in the interceptors for those annotations not being triggered anymore. Here's a sample:
If the above is bootstrapped with standard
@EnableTransactionManagement
the instances handed to the constructor ofInvoker
are JDK proxies and the lookup of the advice chain results in the interceptor for transactions being returned and thus activated. IfproxyTargetClass
is set totrue
, the instances received by the constructor are CGLib proxies and the lookup of the advice chain results in an empty one and thus no transaction is created in the first place.Affects: 4.2.6, 4.3 RC2
Attachments:
Issue Links:
@Transactional
does not appear to work in custom repository implementation@Cacheable
declarations on interface methods@Async
if there is another interceptor1 votes, 9 watchers
The text was updated successfully, but these errors were encountered: