Monday, March 8, 2010

Spring EYE on JAVA EE - 7

Now with the backend services completed, it is time to build the web component by applying Spring MVC module. Actually this development can be parallel to the backend as long as there is clean interface defined. Spring MVC Controller, can be made of POJO, thanks the magic of annotation, that is ideal for testing; yet is still so flexible, that can access HttpServlet objects if necessary, makes it a powerful tool. The View, mainly made of jsp, while Model, need additional tuning to match the view. In this project, a few model objects, which represent a portion of the entity objects, are created to match the view requirement. In some case, the POJO entity object can be used as model object directly credit to not having platform dependency in those classes.


Since this article is mainly focus on the configuration as well as development practice, UI code is omit here. Main codes are the two controller files: StoreController.java and ReportController.java


Key configuration files need to be mentioned are: web.xml, which is pretty standard to all Spring web application, and the default servlet mapping file, springdemo-servlet.xml, that defines view resolver as well as annotation configuration.


POJO controller can be tested by its own just like the above test of DAO DI.


Let’s put all three components together, deploy Spring container inside Tomcat web server, and run the test from the UI. Exception was thrown complaining “No Hibernate Session” in “non-transactional” process. What is wrong? Remember in DAO we delegate the transaction handle to the caller while in unit tests, I add transaction management either programmatically or declaratively so no complains. In this latest integrated test, from the web module to service layer, explicitly declarative transaction management is required. All methods in I_OrderFunction are decorated with @Transactional solves the problem.


I_OrderFunction.java Now the annotations make sense.



Previous    Next

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home