Defaults in Java EE 7 (Tech Tip #37)

Java EE 7 platform added a few new specifications to the platform:

  • Java API for WebSocket 1.0
  • Batch Applications for Java 1.0
  • Java API for JSON Processing 1.0
  • Concurrency Utilities for Java EE 1.0

This is highlighted in the pancake diagram shown below:

javaee7-pancake

Several of the existing specifications were updated to fill the gaps and provide a more cohesive platform. Some small, but rather significant additions, were made to the platform to provide defaults for different features. These defaults would lower the bar for application developers to build Java EE applications.

Lets take a look at them.

  • Default CDI: Java EE 6 required “beans.xml” in an archive to enable CDI. This was mostly a marker file. So you could bundle a completely empty “beans.xml” in the archive and that would enable injection. Of course, you could specify a lot of other elements in this file such as interceptors, decorators, alternative but the basic dependency injection was enabled by just the mere inclusion of this file.This was one of the biggest source of confusion of why beans were not getting injected in a Java EE 7 archive, and was asked on several forums and other channels.

    Java EE 7 made that “beans.xml” optional and provided a default behavior. Now if this file is not bundled, all CDI-scoped beans are available for injection. So any bean with an explicitly specified scope is available for injection. Scopes defined by the CDI specification are listed at docs.oracle.com/javaee/7/api/javax/enterprise/context/package-summary.html. Specifically, here are the scopes defined by CDI:

    • @ApplicationScoped
    • @ConversationScoped
    • @Dependent
    • @NormalScope
    • @RequestScoped
    • @SessionScoped

    In addition, two new scopes are introduced in Java EE 7:

    • @FlowScoped
    • @TransactionScoped

    So, any bean with these scopes will be available for injection, in other beans only, without the presence of “beans.xml”.

    Check it out in action at github.com/javaee-samples/javaee7-samples/tree/master/cdi/nobeans-xml.

  • Default data source: A Java EE runtime, a.k.a application server, requires to package a database with it. If you are building a Java EE application, you likely will need some sort of data store or RBDMS to store the data. So this makes perfect sense.For example, WildFly bundles in-memory H2 database.Now, you can certainly use another JDBC-compliant database but bundling a database makes it convenient to start with. However, in order to get started, Java EE 6 still required to create JDBC resources in an application server-specific way. This would mean understanding app server-specific tools.

    Java EE 7 simplified it by providing a default data source with a pre-defined JNDI name.This mean you can inject a data source as:

    Also, your persistence.xml can look like:

    Note, no <jta-data-source>.

    In both of these circumstances, a default data source with JNDI name java:comp/DefaultDataSource is bound to your application-server specific JDBC resource.

    The exact data source in WildFly can be verified using jboss-cli script as:

    Check it out in action at github.com/javaee-samples/javaee7-samples/tree/master/jpa/default-datasource.

  • Create JMS connection factory, queues, and topics: An application using JMS topics and queues in Java EE 6 would require a deployment script to create Connection Factory and Queues/Topics. These would again be done in an application server-specific way.Java EE 7 provide annotations @JMSConnectionFactoryDefinition and @JMSConnectionFactoryDefinitions that are read by the Java EE 7 runtime and ensures that the ConnectionFactory specified by these annotations is provisioned in the operational environment.

    Similarly, @JMSDestinationDefinition and @JMSDestinationDefinitions can be used to create Topics/Queues as part of application deployment.So no more deployment scripts, just include annotation in your code ?

    Check it out in action at github.com/javaee-samples/javaee7-samples/tree/master/jms/send-receive.

  • Default JMS connection factory: Just like default data source, a default JMS resource allows you to avoid creating a JMSConnectionFactory in an appserver-specific way to deploy the application using JMS resources.Injection of a JMS Producer or Consumer in Java EE 6 required to get an instance of application-managed or container-managed JMSConnectionFactory. This factory had to be manually created in an application-server specific way.Providing a default JMSConnectionFactory simplifies this step further.

    JMS 2.0 also introduced JMSContext as entry point to the simplified API, and it can be injected simply as:

    Not specifying a ConnectionFactory means the default one will be used. And it has the JNDI name of jms/DefaultJMSConnectionFactory.

    The JNDI name may be mapped to the appserver-specific JMS provider. For example, in case of WildFly it is defined as:

    Check it out in action at github.com/javaee-samples/javaee7-samples/tree/master/jms/send-receive.

  • Default executors: Concurrency Utilities for Java EE introduced four different managed objects:
    • ManagedExecutorService
    • ScheduledManagedExecutorService
    • ContextService
    • ManagedThreadFactory

    These objects allow user to create application threads that are managed by the Java EE server runtime. Once again, a default and pre-configured managed object, with a well-defined JNDI name, is made available for each one of them.

    This allows a user to inject a ManagedExecutorService as:

    instead of:

    Default ManagedExecutorService in WildFly can be found as:

    Similarly other default managed objects can be found.

    Check out different executors in action at github.com/javaee-samples/javaee7-samples/tree/master/concurrency.

With so many simplifications, why would you not like to use Java EE 7 platform ?

And WildFly is a fantastic application server too :-)

Download WildFly now, and get started!

Be Sociable, Share!

3 thoughts on “Defaults in Java EE 7 (Tech Tip #37)

  1. Contact Information:

    i-Cell Mobile Telecom INC
    Head Office: 33310 Central Ave, Union City, 94587, United States
    Phone: 510-740-8850 or +1 510-740-8850 (outside United States)
    Fax: +1 912 4 239 5857
    Email: info.ictelecom @ gmail.com
    Skype: info.ictelecom

    i-CELL MOBILE TELECOM is an Approved dealers,specialized in the distributors of Mobile phones,Laptops,Games,Mobile accessories,computer e.t.c. Our objective is to develop long-term relationships with our customers.To do so we continuously provide our existing customers new products, advanced designs, and patented innovations so that they can stay on the top of their markets. We offer a 90 days return policy,and offer a secured & reliable payment method to all our existing & first time buyers.We ship out worldwide through Professional and reliable courier company e.g FEDEX EXPRESS ,DHL and UPS within

    38hrs of contract sealed. Customers never experience what is called Breach of contract since our operation.Fidelity guarantee our service,our product are 100% international warranty and guarantee.Contact us today for your order at our
    marketing.

    Our BONANZA are:

    Buy 2Units and get 1 unit FREE BONUS.

    Buy 5 units and get 2 unit FREE including shipping

    Buy 20 Units and get 5 Units FREE including 10% Discount FREE.

    Why buy from us?
    Lowest Prices Checked,Huge Product Range, 24/7, Online Support, Fast Shipping Guaranteed, Safety and Security assured.Our phones are imported from USA,Finland,Hungary and Singapore; they are factory unlocked, sealed with original packets comes with complete accessory, e.g. charger, extra battery and software c d. The phones are sim free and it’s never lock to any network, specification: (europeans/usa-specifications) general network gsm 900/gsm 1800/gsm 1900 platform – tri band gsm900 + 1800 + 1900 MHz: country of manufactured origin: USA,Finland,Hungary, South Korea and Singapore.All products consist the

    following accessories.

    1. Complete accessories(Well packed and sealed in original company box)

    2. Unlocked / sim free.

    3. Brand new (original manufacturer) box – no copies

    4. All phones have English language as default

    5. All material (software, manual) – car chargers – home chargers – usb data cables -holsters/belt clips – wireless

    headsets(bluetooth) -leather and non-leather carrying cases – batteries.If you are interested, forward your questions and inquires to us via email your order and shipping details. we give 12 Months warranty for every product sold out to our costumers, our product are company tested and approved by global standard organization of wireless industries.

    1. Guarantee 12 Months.
    2. 100% high quality product assurance
    3. Accept the exchange for own defect within 2 weeks
    4. Best after-sale service

    Brands We Stock:

    Samsung Galaxy Note 2
    $270.00
    Samsung Galaxy Note 3
    $280.00
    Samsung Galaxy Note 4
    $300.00

    Samsung Galaxy s5
    $310.00
    Samsung Galaxy s5 Mini
    $320.00
    Samsung Galaxy s4
    $300.00
    Samsung Galaxy s3
    $270.00
    samsung galaxy s4 mini
    $280.00
    samsung galaxy tab 3
    $270.00
    Samsung Galaxy Star Trios S5283
    $270.00

    SONY:

    Sony Xperia Z1 Smartphone (Unlocked, Purple)
    $270.00
    Sony Xperia Z2
    $300.00
    Sony Xperia Go
    $199.00
    Sony Xperia C3 Dual
    $200.00
    Sony Xperia Z2 Tablet LTE
    $299.00
    Sony Xperia E1
    $250.00

    Blackberries:

    Blackberry classic q20
    $350.00
    BlackBerry Z3
    $250.00
    BlackBerry Porsche Design P’9982
    $580.00
    BlackBerry Z30
    $310.00 USD
    Blackberry Q10
    $270.00 USD
    Blackberry Q5
    $260.00 USD
    BlackBerry 4G LTE PlayBook
    $300.00 USD

    HTC:

    HTC One M8 Dual-SIM
    $ PRICE ON REQUEST
    HTC Desire 516 Dual-SIM
    $
    HTC One mini 2
    $
    HTC One Max
    $

    APPLE:

    Apple iPhone 4s
    $
    Apple iPhone 5
    $
    Apple iPhone 5s
    $
    Apple iPhone 5c
    $

    IPAD:

    Apple iPad 4
    $
    Apple iPad Mini
    $
    Apple iPad 5 Air Wi-Fi + 4G 128GB
    $360.00 USD
    Apple iPad 5 Air Wi-Fi + 4G 64GB
    $350.00 USD
    Apple iPad 5 Air Wi-Fi + 4G 32GB
    $300.00 USD
    Apple iPad 5 Air Wi-Fi + 4G 16GB
    $270.00 USD

    KINDLY PLACE YOUR ORDER IN THE BELOW MANNER SO THAT WE CAN PROCEED ON PACKAGING AND LABELING IMMEDIATELY

    FULL NAME ==

    PRODUCTS BRAND AND MODEL ==

    QUANTITY ==

    ADDRESS ==

    CITY ==

    ZIP CODE ==

    COUNTRY ==

    MOBILE/TELEPHONE NUMBER & COUNTRY DIALING CODE==

    RETURN POLICY
    *************
    You may return the item within ten (10)days of delivery of the order.Products with Manufacturer Warranties which exceed 30 days,returned directly to the manufacturer according to their instruction, Customer may request replacement product otherwise Company credit will be issued.

    OUR TERMS
    *********
    We ship to any destination within 38hours by USPS, UPS,DHL, TNT and FedEx Express Service, We give tracking # after confirming your payment for the types and pcs you demand. We use reputable courier services of your choice for Distribution of our goods worldwide!All currency are in United State Dollars, Visit (XE – The World’s Favorite Currency and Foreign Exchange Site)in order to Calculate the cost of conversion of your order.

    SALES & INFO ENQUIRY: +1(510) 740-8850, FAX NO:+1 912 4 239 5857
    Email: info.ictelecom@gmail.com
    Skype: info.ictelecom

    I-CELL MOBILE TELECOM INC TODAY FOR ALL KINDS OF MOBILE PDA AND COMPUTER ACCESSORIES.

Leave a Reply

Your email address will not be published. Required fields are marked *