EE 6 Environmental Enterprise Entries and Glassfish
Two years ago, we decided to move to JEE 6 for our enterprise solutions and take a lot of fun with new EJB 3.1 features and annotations. Glassfish has made our lives easier, it was very easy to declare variables using it’s administration console.
Less complicated than using ejb-jar.xml are two methods using Glassfish server and resources :
I- OLD FASHION WITH RESOURCE PER PARAM (SIMILAR TO ORACLE TUTORIAL)
- Declare an EJB with toBeInjected resource :
- Open admin console ( localhost:4848 by default ) -> Resources -> Custom Resources -> New -> and fill the informations as below
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
At first glance, it looks simple and fast forward but problems start after just after a first project.
Problems ! Why ?
We achieved more than 20 variables and some resource names begin to confuse them. I was very hard for our operations team to catch the name of the correct setting and update its value. It was necessary to group parameters resources into a single resource by project.
NEXT FASHION : GROUPING RESOURCES
In this section I will use scala (similar class can be translated easy to java).
- First of all, we need to create our single resource class as simple bean
- Next, let’s create a resource factory class :
1 2 3 4 5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
The purpose of object factory is to read injectable parameters and populate a resource class
- Jndi Name => the resource name to be used by project for example
- Resource Type => check second radio button, and fill the resource full name ( with package)
- Factory class => Our RessourceFactory class full name ( with package)
- Add two (or more) properties to be injected in our resource class.
1 2 3 4 5 6 7 8
Having a single resource per project facilitates business management and thanks to Glassfish administration console managing JNDI became easier.