RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


The Java EE Application as an EJB/Spring/Hibernate Hybrid : Page 2

Java EE 5 provides all the features you need to build a robust enterprise application right in an EJB 3.0 container, but incorporating the relative strengths of Spring and Hibernate can further improve the productivity and quality of your application.


The Application Example
The example is a simple web application that simply demonstrates the integration of components with read/update operations. Its only functions are accepting a user's ID as input, returning the user's profile, and allowing the user to update the profile. While the general instructions to follow are based on using Eclipse, they should apply to other IDEs as well. (The application is available with the downloadable code.)

First, you need to set up the component model for the application with these steps:

  1. Create an enterprise J2EE project called Account and create a web project in it called AccountWeb.
  2. Add the Java EE 5 libraries (javaee5.jar) of your application server to the build path.
  3. Create a directory called "lib" under the EAR project where you will place all the application JARs. All projects in the EAR will refer to these libraries.

Figure 1shows the overall component model.

Click to enlarge

Figure 1. Overall Component Model:
Here is the component model for the application example.

Next, you build the presentation tier by creating an index.jsp page and using Spring MVC to hook it up to the appropriate controller and the response page (refer to Figure 1). To complete a standard MVC configuration, add the URL mapping and view resolver to the configuration file springapp-servlet.xmlas follows:

<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
   <property name="mappings">
		<prop key="/edit.act">springAppController</prop>

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
   <property name="viewClass">
   <property name="prefix">
    <property name="suffix">

Next, initialize springapp-servlet.xml through the web.xmlas follows:


Your web project tree should look like Figure 2now.

Click to enlarge

Figure 2. Web Project Tree:
Here is how your web project tree should look.

At this point you can transition from the presentation tier to the business tier, where you will implement the business logic for the application example as a stateless session bean.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date