[英]spring @PostConstruct not firing in JBoss7
更新在WebSphere和Netweaver中運行的應用程序以在JBoss6.2 EAP中運行后,我遇到了麻煩。
我發現使用@PostConstruct(javax.annotation.PostConstruct)注釋的init()方法的Spring管理的@Repository(org.springframework.stereotype.Repository)在JBossEAP中部署時沒有運行init()方法6.2.0。
該類看起來如下所示:
package com.company.productname.api.dao.impl;
// ... imports removed ....
@Repository
public class UserRoleDao extends AbstractBaseDao {
private static final Log LOG = LogFactory.getLog(UserRoleDao.class);
private boolean testInitInvoked = false;
// .... some code removed ....
/**
* Prepare the caches used to lookup market roles
*/
@PostConstruct
protected void init() {
testInitInvoked = true;
if (LOG.isDebugEnabled())LOG.debug("UserRoleDao.init() method called");
// .. . . . some code removed ......
}
@Override
public Mask getMask(final String aMaskName) {
LOG.debug("getRoleMask entered, testInitInvoked = [" + testInitInvoked + "]- aMaskName = " + aMaskName);
Mask myMask = masksByName.map().get(aMaskName);
if (myMask != null) {
myMask.setMembers(this.getMembersForMaskId(myMask.getId()));
}
LOG.debug("getRoleMask returning - myMask = " + myMask);
return myMask;
}
}
我從日志記錄中看到的是,init方法中的日志記錄沒有被記錄,並且當應用程序使用該類時,testInitInvoked布爾值的值保持為false(啟動后的一段時間)。
上面的類是一個捆綁在war / WEB-INF / lib中的jar。
我可以從spring日志中看到UserRoleDao類被自動連接到使用@Autowired注釋引用它的類中。
彈簧罐安裝在JBoss的JBOSS_HOME \\ modules \\ com \\ company \\ thirdparty \\ main中,並由module.xml文件正確引用(因為大多數應用程序是spring管理的,我知道它們被正確引用)。
spring上下文使用類掃描,如以下摘自spring context xml文件所示:
<context:component-scan base-package="com.company.productname.api" />
所以,奇怪的是spring能夠將UserRoleDao類自動裝入使用它的Service類中,但@PostConstruct似乎被忽略了。
我已經嘗試將spring jar移動到WEB-INF \\ lib目錄中(我發現以前圍繞Hibernate的問題是,如果在JBOSS_HOME \\ modules中引用了jar並將它們移動到WEB-INF \\ lib目錄中,那么注釋就不會被掃描固定的)。
之前有沒有人注意到類似的問題? (並找到了解決方案!)
使用相同的spring版本jar在WebSphere和Netweaver中部署時,會觸發@PostConstruct init方法。
如果我在錯誤的地方發布了這個,請道歉,請告訴我,我會移動它。
謝謝,
版本:
JBoss:EAP 6.2.0.GA(基於AS 7.3.0構建)
春天:3.1.1
添加依賴項
<module name="javax.annotation.api" export="true"/>
彈簧模塊適合我。
感謝M. Deinum的建議,我能夠解決這個問題。 我必須將spring jar放在我的WEB-INF / lib目錄中,然后將它們從modules目錄中刪除。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.