views:

74

answers:

1

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 BusinessInterceptor have not been initialized properly.

+1  A: 

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 :)

ewernli
+1 for the little but extremely important digression.
Pascal Thivent