In the previous article, we have created the related classes between the layers, and this article focuses on how to manage dependencies between classes through spring.
Step Eight: Manage the dependencies between classes through spring.
Applicationcontext.xml
<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://www.springframework.org/schema/beans" xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:p= "http://www.springframework.org/schema/p" xsi: schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans-2.0.xsd "><bean id=" DataSource "class=" Org.apache.commons.dbcp.BasicDataSource ">< Property Name= "Driverclassname" value= "Com.mysql.jdbc.Driver" ></property><property name= "url" value= " Jdbc:mysql://localhost:3306/mytest "></property><property name=" username "value=" root "></ Property><property name= "Password" value= "root" ></property><property name= "maxactive" value= "100 "></property><property name=" Maxidle "value=" "></property><property name=" maxWait "value = "$" ></property><property name= "Defaultautocommit" value= "true" ></property></bean> <bean id= "sessionfActory "class=" Org.springframework.orm.hibernate3.LocalSessionFactoryBean "><property name=" DataSource "ref= "DataSource" ></property><property name= "hibernateproperties" ><props><prop key= " Hibernate.dialect ">org.hibernate.dialect.mysqldialect</prop><prop key=" Hibernate.show_sql ">true </prop></props></property><property name= "Mappingresources" ><list><value> Com/tgb/bean/user.hbm.xml</value></list></property></bean><bean id= "UserDao" class= " Com.tgb.dao.impl.UserDAOImpl "scope=" singleton "><property name=" sessionfactory "><ref bean=" Sessionfactory "/></property></bean><bean id=" UserService "class=" Com.tgb.service.impl.UserServiceImpl "><property name=" Userdao "><ref bean=" Userdao "/></property ></bean><bean id= "saveuseraction" class= "com.tgb.action.user.SaveUserAction" ><property name= " UserService "><ref bean=" UserService "/></property></bean><bean id= "listuseraction" class= "Com.tgb.action.user.ListUserAction" > <property name= "UserService" ><ref bean= "UserService"/></property></bean></beans>
We can view the dependencies between the classes configured in Applicationcontext.xml through Spring Explorer , as follows:
Step Nine: Manage the display of JSP pages through Web. Xml.
Xml
<?xml version= "1.0" encoding= "UTF-8"? ><web-app version= "2.5" xmlns= "Http://java.sun.com/xml/ns/javaee" Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http ://java.sun.com/xml/ns/javaee/web-app_2_5.xsd "><filter><filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class></filter>< filter-mapping><filter-name>struts2</filter-name><url-pattern>/*</url-pattern></ filter-mapping><welcome-file-list><welcome-file>index.jsp</welcome-file></ Welcome-file-list><listener><listener-class> Org.springframework.web.context.contextloaderlistener</listener-class></listener></web-app>
In this, we have completed all the work of struts2+hibernate3.2+spring2.0 integration, publish the project to Tomcat and see how it works.
Source: Http://pan.baidu.com/s/1mgHXqoo.
STRUTS2+HIBERNATE3.2+SPRING2.0 Integration Chapter (III)