![](/img/trans.png)
[英]Getting nullpointerException while using the jdbcTemplate in spring
[英]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.