@Singleton, @Startup, @PostConstruct does not work on EJB3.1 and Glassfishv3.0.1

I have a problem with this installation and I can’t even view the logs.

This is my @Singleton @Startup EJB:

 @Singleton @Startup @DependsOn("SchedulerEJB") public class SchedulerStartUp { private static Logger log = Logger.getLogger(SchedulerStartUp.class); @EJB SchedulerEJB schedEJB; @PostConstruct public void atStartup() { log.info("startUp") System.out.println("startUp"); schedEJB.cancelTimer("EBlastScheduler"); schedEJB.createTimer("*/1", "*", "*"); } } 

SchedulerEJB :

  @Stateless public class SchedulerEJB { @Resource TimerService timerService; public cancelTimer(String timerInfo){/*...*/} public createTimer(String sec, String min, String hour) {/*...*/} @Timeout public void execute(Timer timer) {/*...*/} } 

Maven pom:

  //Been Using Glassfishv3.0.1 and EJB3.1 with a dependency of: <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>6.0</version> <scope>provided</scope> </dependency> 
+6
source share
1 answer

You have an invalid bean type as the @DependsOn attribute. DependsOn is intended to express the dependency between two Singleton beans sessions, not between Singleton and Stateeless. You must change SchedulerEJB to Singleton or remove the dependency.

If you decide to change SchedulerEJB to Singleton, then @DepensOn is also not needed, because (from the EJB 3.1 specification):

Note that if one Singleton just needs to call another singleton from the PostConstruct method, no explicit ordering metadata is required. In this case, the first singleton would simply use the ejb link to invoke the target Singleton. There, acquiring an ejb link (either by injection or by searching) does not necessarily imply the actual creation of the corresponding Singleton bean instance.

+6
source

Source: https://habr.com/ru/post/904130/


All Articles