Am I allowed to declare a lifecycle interceptor on an interceptor?
I have my business bean defined thus:
@Local
@Interceptors(BusinessInterceptor.class})
public class MyBean implements SomeBean { ... }
And then I want my BusinessInterceptor
to be configured with Spring's SpringBeanAutowiringInterceptor
:
@Interceptors(SpringBeanAutowiringInterceptor.class)
public class BusinessInterceptor {
@Autowired
private SomeSpringBean someSpringBean;
}
Is this allowed/legal? I'm getting errors (NPEs, mostly) suggesting that the fields in B开发者_运维知识库usinessInterceptor
have not been initialized properly.
I doubt this can work. If I understand well your scenario, you have basically two DI containers, one is Spring and the other the app. server itself. Each one manages different elements. The BusinessInterceptor
is created by the app. server which is unaware of Spring -- the @Autowired
bean is then not set.
( Note that Spring and EJB3 have become quite similar now. You can have the same functionalities as EJB with Spring. Spring has indeed declarative transactions, dependency injection and AOP facilities similar to EJB3 interceptors (these are the main managed features). On the other hand, EJB3 is now so lightweight that there isn't really a compelling reason to use Spring with with EJB3. See Future of enterprise Java: full stack Spring or full stack Java EE. But this does not answer the question, and is just a little digression of mine :)
精彩评论