我有一个场景,我需要在应用程序启动时加载一个 bean (ReportManager),以便它可以安排执行报告(由 DataStore bean 从数据库轮询)。
谷歌搜索我发现了@Singleton、@Startup 和@DependsOn 注释,我使用过这样的注释:
@Singleton
@Startup
@DependsOn("DataStore")
public class ReportManager {
@EJB
DataStore dataStore;
@PostConstruct
public void scheduleReports() {
logger.log("INITIALIZED");
List<Report> reports = dataStore.getReports();
....
}
}
@Singleton
@RolesAllowed("user") //I had security checks implemented like that beforehand
public class DataStore {
@PostConstruct
public void initialize() {
logger.log("INITIALIZED");
}
public List<Report> getReports() {
...
}
}
问题是我在部署期间遇到了非常奇怪的异常:
<2012-09-27 14:04:15 CEST> <Warning> <Deployer> <BEA-149004> <Failures were detected while initiating deploy task for application "app".>
<2012-09-27 14:04:15 CEST> <Warning> <Deployer> <BEA-149078> <Stack trace for message 149004
weblogic.application.ModuleException: Exception starting module: EJBModule(app-ejb-1.0-SNAPSHOT.jar)
Unable to deploy EJB: ReportManager from app-ejb-1.0-SNAPSHOT.jar:
Singleton ReportManager(Application: app, EJBComponent: app-ejb-1.0-SNAPSHOT.jar) failed to initialize.
at weblogic.ejb.container.deployer.EJBModule.start(EJBModule.java:592)
.....
Caused By: weblogic.ejb.container.InternalException: Transaction marked rollback or not expected transaction status: 1
at weblogic.ejb.container.manager.SingletonSessionManager.postCallback(SingletonSessionManager.java:464)
不是真正有用的异常消息。特别是我也没有得到任何“初始化”日志条目。当我注释掉 dataStore.getReports() 调用时,一切正常,bean 以正确的顺序构造(产生了“INITIALIZED”消息)。包括 dataStore 方法调用导致了上述错误,并且以某种方式抑制了所有日志输出。
我正在使用 Weblogic 12c。