我试图使用@Interceptors(SpringBeanAutowiringInterceptor.class)
将Spring bean注入到EJB中,但我无法使用我见过的beanRefContext.xml
示例。向EJB3注入Spring bean
这里是我的EJB:
@Stateless
@Interceptors(SpringBeanAutowiringInterceptor.class)
public class AlertNotificationMethodServiceImpl implements
AlertNotificationMethodService {
@Autowired
private SomeBean bean;
}
我提供了一个beanRefContext.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="...">
<!-- Have also tried with ClassPathXmlApplicationContext -->
<bean id="context"
class="org.springframework.web.context.support.XmlWebApplicationContext">
<property name="configLocations" value="/config/app-config.xml" />
</bean>
</beans>
但是,它似乎是重新创建豆,而不是获取现有的ApplicationContext。我最终得到下面的异常,因为我的一个bean是ServletContextAware。
java.lang.IllegalArgumentException: Cannot resolve ServletContextResource
without ServletContext
当使用SpringBeanAutowiringInterceptor
,它不应该获得的ApplicationContext,而不是创建一个新的?
我也尝试更改我的web.xml,所以contextConfigLocation指向beanRefContext.xml,希望它会加载我的Spring配置,但最终得到与上面相同的异常。
有谁知道如何正确地做到这一点?我见过的例子似乎使用了我使用的相同的方法,我假设这意味着在调用Interceptor时(或者它应该如何工作并且我误解了它),bean会被重新创建。
一个有用的链接解释的全过程:http://techo-ecco.com/blog/spring-application-context-hierarchy-and-contextsingletonbeanfactorylocator/ – omartin 2013-02-06 08:42:30