相关疑难解决方法(0)

将Spring bean注入EJB3

我正在尝试将Spring bean注入到EJB中,@Interceptors(SpringBeanAutowiringInterceptor.class)但是我无法使用beanRefContext.xml我见过的示例.

这是我的EJB:

@Stateless
@Interceptors(SpringBeanAutowiringInterceptor.class)
public class AlertNotificationMethodServiceImpl implements
        AlertNotificationMethodService {

    @Autowired
    private SomeBean bean;
}
Run Code Online (Sandbox Code Playgroud)

我提供了一个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>
Run Code Online (Sandbox Code Playgroud)

但是,它似乎正在重新创建bean而不是获取现有的ApplicationContext.我最终得到以下异常,因为我的一个bean是ServletContextAware.

java.lang.IllegalArgumentException: Cannot resolve ServletContextResource
without ServletContext
Run Code Online (Sandbox Code Playgroud)

使用时SpringBeanAutowiringInterceptor,是不是应该获取ApplicationContext而不是创建一个新的?

我也试过更改我的web.xml,所以contextConfigLocation指向beanRefContext.xml,希望它加载我的Spring配置,但我最终得到了与上面相同的异常.

有谁知道如何正确地做到这一点?我看到的示例似乎使用了我正在使用的相同方法,我假设这意味着在调用Interceptor时正在重新创建bean(或者它是如何工作的,我误解了).

spring dependency-injection ejb-3.1

9
推荐指数
1
解决办法
1万
查看次数

标签 统计

dependency-injection ×1

ejb-3.1 ×1

spring ×1