开发者

can spring inject EJBs into annotated fields of servlet in a Java SE webapp?

Spring has support for injecting javax.ejb.EJB annotations, much like it injects @Autowired and other jsr-220 injection annotations, thanks to the CommonAnnotationBeanPostProcessor class.

However, injection doesn't work for servlets, since the servlet isn't created by spring.

This article - Spring injects servlets too - doesn't give开发者_如何学C an example using servlets, but claims it's possible using compile-time weaving of aspects. Unfortunately, compile-time weaving is not an option for us. Is it possible to do this at runtime? It's ok to introduce a subclass to the servlet if that helps, but I want to keep EJB annotations so the servlets can still deployed in a Java EE container.

EDIT: The app will be deployed to a Java EE container in production, but I was thinking of using spring for running functional tests and for local deployment for development to take advantage of hot JSP loading in Tomcat.


You will need Java EE container like in Glassfish that supports injection of EJBs and beware that injection works on managed classes like servlets, managed beans..etc (classes that are managed by containers) so ejb injection in normal classes would require you to use lookups instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜