Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

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.


advertisement
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 1 shows 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.xml as follows:

<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <prop key="/edit.act">springAppController</prop> </props> </property> </bean> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass"> <value>org.springframework.web.servlet.view.JstlView</value> </property> <property name="prefix"> <value></value> </property> <property name="suffix"> <value>.jsp</value> </property> </bean>

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

<servlet-name>springapp</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

Your web project tree should look like Figure 2 now.

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.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap