4/17/2010

Env-entry enhancement in JavaEE 6

JavaEE 6 adds 2 additional types to the list of env-entry types: java.lang.Class and any enum type. So there are now 11 portable env-entry types that must be supported by all compliant application servers:

       java.lang.Class
any enum type
java.lang.Boolean
java.lang.Byte
java.lang.Character
java.lang.String
java.lang.Short
java.lang.Integer
java.lang.Long
java.lang.Float
java.lang.Double
For example, to use java.lang.Class and enum env-entry-type in a web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<env-entry>
<description>example of java.lang.Class env-entry-type</description>
<env-entry-name>java:app/env/myImplClass</env-entry-name>
<env-entry-type>java.lang.Class</env-entry-type>
<env-entry-value>test.MyServiceProvider</env-entry-value>
</env-entry>

<env-entry>
<description>example of enum env-entry-type</description>
<env-entry-name>java:app/env/day</env-entry-name>
<env-entry-type>com.examplexxx.util.Day</env-entry-type>
<env-entry-value>SUNDAY</env-entry-value>
</env-entry>
</web-app>
To inject the above 2 env-entry into fields in a servlet, or EJB bean class, or any other components in the EAR:
@Resource(lookup="java:app/env/myImplClass")
@SuppressWarnings("unchecked")
private Class myImplClass;

@Resource(lookup="java:app/env/day")
private com.examplexxx.util.Day day;
For java.lang.Class type, only the raw type, not the generic type, can be declared as the field type, hence @SuppressWarnings("unchecked").

2 comments:

Anna said...

Great and Useful Article.

Online Java Course

Java Online Training

Java Course Online

J2EE training

online J2EE training

Best Recommended books for Spring framework

Java Interview Questions












Java Training Institutes in Chennai

Java Training in Chennai

J2EE Training in Chennai

java j2ee training institutes in chennai

Vũ Diệu Linh said...

I enjoyed on reading your blog post. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. Please visit my website, Friv 4000 Games is where all the free friv games.
Friv 4000