简体   繁体   中英

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

I have an existing application developed using Spring 2.5, which I had to migrate to 3.2.6. After the migration, everything is working fine.. except I'm getting a NullPointerException while using onEjbCreate() method of Deprecated AbstractStatelessSessionBean in Spring 3.2.6 . I think the problem is that onEjbCreate() is not compatible with EJB 3.0. I tried using @PostConstruct ,but then I was not able to get what to substitute for the existing getBeanFactory() .

Would appreciate if anyone can help me with this. Thanks.

This is the existing code that was working on Spring 2.5

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

As you noticed AbstractStatelessSessionBean is deprecated in favor of EJB3 style implementation and in Spring 4.0 it is removed altogether.

For EJB3 the Spring provides SpringBeanAutowiringInterceptor

Having that you can simply using this:

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

   @Autowired
   private ConnectionFactory mqConnectorFactory;

}

Of course, you should be sure that you configure Spring correctly: beanRefContext.xml in the classpath.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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