I had a scenario in which I needed one bean (ReportManager) to be loaded at application startup, so it can schedule reports for execution (polled from database by DataStore bean).
Googling around I found @Singleton, @Startup and @DependsOn annotations, which I've used like this:
@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() {
...
}
}
The problem was that I was getting really strange exception during deployment time:
<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)
Not really heplful exception message. Especially that I was also not getting any "INITIALIZED" log entries. When I commented out the dataStore.getReports() invocation everything was working fine and beans were constructed in proper order ("INITIALIZED" messages were produced). Including dataStore method invocation was causing above error and was somehow supressing all the log output.
I am using Weblogic 12c.