Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EJB3 initialization code

I've searched this for a while now, but can't seem to find an answer to this. How can I execute some code in when deploying an EJB3 jar-file to a JBoss server? For example, I need to run some sql migration scripts before the beans are ready to be used.

like image 437
semonte Avatar asked Dec 06 '25 05:12

semonte


2 Answers

If you can't use EJB 3.1 (with @Singleton @Startup), I would recommend packaging your EJB module in an EAR with a WAR. Add a ServletContextListener to the WAR, and take your action in the contextInitialized method.

like image 152
Brett Kail Avatar answered Dec 12 '25 00:12

Brett Kail


You can create a JBoss MBean service with a Listener that can perform any initialization (SQL scripts run in your case) after JBoss is fully started and before any EJB is used. I have created such a service and we run it on JBoss 4.2.3.GA, so, you do not need to migrate to JBoss 7.

like image 28
Igor Urdenko Avatar answered Dec 12 '25 00:12

Igor Urdenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!