DI in EJB / MDB Application

I am currently developing a small EJB application running on IBM Websphere Application Server 7 (Java EE 5). The application basically consists of one MDB, which listens for incoming MQ messages, which are converted and stored in the database. I currently use a lot of Singleton / Factories for sharing configurations, comparisons, data searches, etc. But this actually leads to very complex code testing. The solution can use a (simple) DI structure, such as guice / spring, to input different instances. The question is: where to place the initialization / configuration code? Where is the main entry point of the application? How can I inject instances in MDB?

+4
source share
2 answers

it might be worth taking a look at the rollback from using Guice and trying to work with the injection mechanisms that are already available with Java EE 5.

Regarding finding a suitable β€œstarting point”, unfortunately, the EJB specification does not define the way you can run a bean at startup. However, the EE specification web profile has one thing: you can add a WAR to your application and install the servlet listener component:

http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContextListener.html

You can set this to run when the application is loaded and launched by the container (WebSphere). However, pay attention to problems with class loaders.

+2
source

All Articles