JBoss EAP6 for Spring users

Writing Spring applications the JBoss way

Marius Bogoevici
Senior Software Engineer, Red Hat, Inc.

Goal for today?

Learn how to be a more productive Spring developer with JBoss technologies

Agenda

  • Conventional wisdom
    • Spring and Java EE integration
    • Starting quickly
    • Enhancing Spring projects with Snowdrop
  • The bleeding edge
    • Testing Spring with Arquillian
    • Mixing Spring and CDI
    • Starting Spring projects with Forge

Conventional wisdom

Spring + JBoss

(the basics)

Spring 101: the Spring triangle

Programming model

     
  • Platform independent
  • Business concepts
  • Oblivious of infrastructure
  • 99% development time spent here!

Portable service abstractions

     
  • Backing the programming model
  • Decoupling the runtime for platform
  • ~1% of development time spent here
  • ... and 99% of production time!

Spring and Java EE

JBoss services

Standard Java EE

  • Data access: pooled datasources
  • <jee:jndi-lookup id="dataSource"
                jndi-name="java:jboss/datasources/ExampleDS"
                expected-type="javax.sql.DataSource"/>
  • Entity persistence via JPA
  • <jee:jndi-lookup id="entityManager"
                    jndi-name="java:comp/env/hello/EntityManager"
                    expected-type="javax.persistence.EntityManager"/>

JBoss services

Standard Java EE

  • Transaction service via JTA
  • <tx:jta-transaction-manager/>
  • Messaging: message broker (HornetQ), JCA
  • <jms:jca-listener-container
                   resource-adapter="resourceAdapter"
                   acknowledge="auto"
                   activation-spec-factory="activationSpecFactory">
            <jms:listener destination="/queue/sportsclub"
                           ref="paymentNotificationProcessor"
                           method="processPaymentNotification"/>
          </jms:jca-listener-container>
          
          <jboss:activation-spec-factory id="activationSpecFactory" />
          
          <jboss:resource-adapter id="resourceAdapter"/>
          
          <jee:jndi-lookup id="jcaConnectionFactory"
                              expected-type="javax.jms.ConnectionFactory"/>

    (JBoss namespace provided by Snowdrop)

JBoss services

JBoss-specific

  • Clustering
    • e.g. web session, second-level cache
  • Caching (Infinispan)
    • via Spring 3.1 caching support and Infinispan-Spring integration

JBoss services

Runtime-provided

  • Modular classloading
  • Annotation Scanning
  • Domain Management

Tip #1

Creating powerful Spring applications on JBoss AS can be a simple matter of choosing the right configuration options.

How to get started?

  • Archetypes and quickstarts
  • Running in the cloud

Demo

Starting fast with the JBoss Developer Studio

Demo

Running in the cloud with OpenShift

Tip #2

JBoss Tools and Developer Studio, as well as JBoss archetypes can help you with getting the configuration options right.

Deeper integration with Snowdrop

Enrich the experience of Spring users developing on JBoss AS

How Snowdrop works

What brings Snowdrop new?

  • Adding JBoss-specific functionality
    • e.g. application context bootstrapping
  • Provide custom namespaces for JBoss
    • shorter, portable definitions
  • Replacement implementations for missing or incorrect Spring functionality
    • load-time weaving, resource scanning
    • contributed to the Spring Framework

Tip #3

Use Snowdrop for getting additional functionality, simplify configuration and closing the gap with older Spring versions

The bleeding edge

Testing Spring applications with Arquillian

  • Arquillian: beyond unit tests
  • Fully configured in-container tests
  • Integrate with JUnit and TestNG (and your IDE)

Arquillian Spring extension

  • In-container Spring context deployment
  • Spring bean injection
  • Artifact packaging
  • Support for custom Spring context classes

Tip #4

Exercise the real infrastructure of your application with Arquillian's Spring extension

Integrating Spring and CDI

Why?

  • Reuse existing investments
  • Integrate groups with various expertise
  • Simplify integration of Spring and Java EE
  • Ease migration of Spring applications to Java EE 6

Features

  • Integrating Spring components into CDI
    • Accessing Spring application contexts as CDI beans
    • Making Spring beans available as CDI beans
  • Accessing CDI beans
    • Exposing CDI beans to Spring

Demo - Spring CDI integration

Beyond CDI

Tip #5

Use your business code across technology lines!

Spring MVC Forge plugin

Features

  • Adding Spring libraries to the project
  • Creating Spring persistence infrastructure (beans)
  • Creating Spring-based DAOs
  • Scaffolding Spring MVC views from entities
  • Integrates seamlessly with Java EE features

Demo - Spring Forge Plugin

Tip #6

Use JBoss Forge to stay away from all kinds of boilerplate

Is there a tip #7?

Can I get support?

Web Framework Kit

  • Companion product to JBoss EAP6
  • WFK2: June 2012
  • Includes Snowdrop 2.0
  • Certifies Spring Framework 2.5,3,3.1
  • Certifies Spring Security, Webflow, Web Services