1

Using CDI is there a way to cause a bean to be instantiated when the application server starts up?

I would like to be able to do something like:-

@Singleton
@Startup
public class StartupBean {
...
}

Unfortunately, although the @Singleton annotation exists in the javax.inject.* package the @Startup annotation doesn't.

cbl.adp
  • 244
  • 1
  • 4
  • 16

1 Answers1

4

Use both of those from the javax.ejb.* package. EJBs support CDI and you can kick off anything you want.

rdcrng
  • 3,415
  • 2
  • 18
  • 36
  • Note that a CDI \@ApplicationScoped class is not single-threaded like en EJB marked with \@Startup & \@Singleton. – gkephorus Nov 03 '14 at 12:31