Java Virtal Machine.net

[ News ] rss

February 01, 2011

Mark Wielaard: New GPG key. Finally created a new GPG key using gnupg. The old one was a DSA/1024 bits one and 8 years old. The new one is a RSA/2048 bits one. I will use the new one in the future to sign any release tarballs I might create. pub 2048R/57816A6A 2011-01-29 Key f...

More »

February 01, 2011

Andrew Hughes: [SECURITY] IcedTea6 1.7.8, 1.8.5, 1.9.5 Released!. We are pleased to announce a new set of security releases, IcedTea6 1.7.8, IcedTea6 1.8.5 and IcedTea6 1.9.5. This update contains the following security updates: The IcedTea project provides a harness to build the source code from OpenJDK6 u...

More »

November/2024
SunMonTueWedThuFriSat
     12
3456789
10111213141516
17181920212223
24252627282930
       

[ Archives News
for 'Java Technology' ]

home > news > java technology > applicaction configuration in java ee 6 using cdi - a simple example

Applicaction configuration in Java EE 6 using CDI - a simple example

CDI (Contexts and Dependency Injection for the Java EE platform) is defined in JSR-299 and enhances support for dependency injection in Java EE 6. The more I use CDI the more I like it...However, I couldn't find a simple example of how to configure your application with CDI by reading configuration attributes from a file. Here is an example of how it can be done: Specifying injection points Injection points are places where CDI will inject values automatically. They can be used to receive references to container objects like PersistenceUnit or Transaction manager, and also to receive configuration values. One specifies a injection point by annotating a field, constructor parameter or method parameter with the @Inject annotation. When the container finds this annotation it will try to find (or construct) a value to be stored at this point. Just using @Inject is not enough for configuration, because the container will not know where we want it to get the configuration from. We will need to create a configuration factory, but before that we need to define an additional annotation to provide a hint about where the value will be coming from. This annotation is called a Qualifier annotation exactly because it qualifies the information to be injected. In this example we will create the @Config annotation: @Qualifier @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARA...


Date: May, 18 2010
Url: http://www.java.net/blog/jjviana/archive/2010/05/18/applicaction-configuration-java-ee-6-using-cdi-simple-example


Others News

©2002-2019Java-Virtual-Machine.net https://mobirise.com/ | website editor | static website generator | easy website builder software | bootstrap popup