繁体   English   中英

使用EJB 3在Spring 3.2.6中使用Deprecated AbstractStatelessSessionBean的onEjbCreate方法时获取NullPointerException

[英]Getting NullPointerException while using onEjbCreate method of Deprecated AbstractStatelessSessionBean in Spring 3.2.6 with EJB 3

我有一个使用Spring 2.5开发的现有应用程序,我必须迁移到3.2.6。 迁移之后,一切都运行正常..除了我在Spring 3.2.6中使用Deprecated AbstractStatelessSessionBean onEjbCreate()方法时遇到NullPointerException 我认为问题是onEjbCreate()与EJB 3.0不兼容。 我尝试使用@PostConstruct ,但后来我无法获得替代现有getBeanFactory()

如果有人能帮助我,我将不胜感激。 谢谢。

这是在Spring 2.5上运行的现有代码

@Override
protected void onEjbCreate() throws CreateException {
    mqConnectorFactory = (ConnectorFactory) getBeanFactory().getBean(BEAN_NAME_MQ_CONN_FACTORY);
}

正如您所注意到的那样, deprecated AbstractStatelessSessionBean以支持EJB3样式的实现,而在Spring 4.0中,它被完全删除。

对于EJB3,Spring提供了SpringBeanAutowiringInterceptor

有了这个你可以简单地使用这个:

@Stateless
@Interceptors(SpringBeanAutowiringInterceptor.class)
public class MyEjb {

   @Autowired
   private ConnectionFactory mqConnectorFactory;

}

当然,您应该确保正确配置Spring:类路径中的beanRefContext.xml

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM