我正在尝试使用以下方法将 Spring beans 注入到 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 配置,但我最终遇到了与上面相同的异常。
有谁知道如何正确执行此操作?我看到的例子似乎使用了与我正在使用的相同的方法,我认为这意味着在调用拦截器时正在重新创建bean(或者它应该如何工作,但我误解了)。