2014-04-02 32 views
0

我有一个使用Spring 2.5开发的现有应用程序,我必须迁移到3.2.6。 迁移后,一切工作正常..除了我得到NullPointerException,而在Spring 3.2.6中使用onEjbCreate()方法的弃用AbstractStatelessSessionBean。 我认为这个问题是onEjbCreate()与EJB 3.0不兼容。 我尝试使用@PostConstruct,但后来我无法获得什么替代现有的getBeanFactory()在Spring 3.2.6和EJB 3中使用onEjbCreate方法废弃AbstractStatelessSessionBean时得到NullPointerException

希望有人能帮助我。 谢谢。

这是现有的代码,是在春季2.5

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

'AbstractStatelessSessionBean'不是EJB3它是EJB2,所以它不会像那样工作。有关EJB3集成,请参见[参考指南](http://docs.spring.io/spring/docs/4.0.3.RELEASE/spring-framework-reference/htmlsingle/#ejb-implementation-ejb3) –

回答

2

工作正如你注意到AbstractStatelessSessionBeandeprecated有利于春季4.0 EJB3风格执行和它完全删除。

对于EJB3的Spring提供SpringBeanAutowiringInterceptor

有,你可以简单地使用这样的:

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

    @Autowired 
    private ConnectionFactory mqConnectorFactory; 

} 

当然,你应该确保你正确配置Spring:在classpath beanRefContext.xml