我正在尝试将 Spring bean 注入到 EJB 中,@Interceptors(SpringBeanAutowiringInterceptor.class)
但我无法使用beanRefContext.xml
我见过的示例使其工作。
这是我的 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>
但是,它似乎是重新创建 bean 而不是获取现有的 ApplicationContext。我最终得到以下异常,因为我的 bean 之一是 ServletContextAware。
java.lang.IllegalArgumentException: Cannot resolve ServletContextResource
without ServletContext
使用时SpringBeanAutowiringInterceptor
,不应该获取ApplicationContext而不是创建一个新的吗?
我还尝试更改我的 web.xml,以便 contextConfigLocation 指向 beanRefContext.xml,希望它会加载我的 Spring 配置,但我最终会遇到与上述相同的异常。
有谁知道如何正确地做到这一点?我看到的示例似乎使用了我正在使用的相同方法,我认为这意味着在调用 Interceptor 时正在重新创建 bean(或者它应该如何工作并且我误解了)。