This article for Bo Master original, allow reprint, but please declare the original address: http://www.coselding.cn/blog/8/8-151.html
Version:
struts:struts-2.3.24.1
spring:spring-framework-4.2.5
hibernate:hibernate-release-5.1.0
Struts2
1, the introduction of STRUTS2 base jar package;
Commons-fileupload-1.2.2.jar
Commons-io-2.0.1.jar
Commons-lang-2.5.jar
Commons-logging-1.1.1.jar
Freemarker-2.3.16.jar
Javassist-3.11.0.ga.jar
Ognl-3.0.1.jar
Struts2-core-2.2.3.jar
Xwork-core-2.2.3.jar
Asm-3.1.jar
Asm-commons-3.1.jar
2. Web. XML Configuration Struts2 Interceptor:
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
3, Web-inf under the creation of JSP folder, the inside to create a feedback JSP page;
4. Create action: Inherit Actionsupport rewrite Excute method;
5, Classpath under the establishment of Struts.xml:
Configure the action:
<action name= "register" class= "Com.s2sh.action.RegisterAction" >
<result name= "Success" >/WEB-INF/jsp/success.jsp</result>
<result name= "fail" >/WEB-INF/jsp/fail.jsp</result>
</action>
Spring
1. Import Spring's base jar package;
2. Set the spring configuration file location:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
Classpath:applicationContext.xml
</param-value>
</context-param>
3. Set spring to start with server startup
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
4. Create Applicationcontext.xml under Classpath
To configure the component Bean Scan path:
<context:component-scan base-package= "Com.s2sh" ></context:component-scan>
5, join and STRUTS2 connection plug-in: Struts2-spring-plugin-2.3.24.1.jar;
6, write good DAO and service, with @component and @resource annotation good bean component and automatic injection;
7. Add the required business processing class reference in action, add the set and get methods so that spring will inject it automatically;
8. Configure spring's Chinese garbled filter;
Hibernate
1. Join hibernate base jar package;
2. Join the connection Pool jar package:
C3p0-0.9.2.1.jar
Mchange-commons-java-0.2.3.4.jar
3, join SLF4J and log4j and other related log package
Database driver Package
Aopalliance-1.0.jar
4, Classpath create jdbc.properties, configure the JDBC database connection information;
5, applicationcontext.xml Configuration load JDBC Information file:
<context:property-placeholder location= "Classpath:jdbc.properties"/>
6. Applicationcontext.xml Configure database Connection pool objects:
<bean id= "DataSource" class= "Com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method= "Close" >
<property name= "Driverclass" value= "$ {jdbc.driverclassname}"/>
<property name= "Jdbcurl" value= "$ {jdbc.url}"/>
<property name= "User" value= "$ {jdbc.username}"/>
<property name= "Password" value= "$ {jdbc.password}"/>
</bean>
7. Configure sessionfactory (equivalent to Hibernate's main profile):
<!--integrated Hibernate--
<bean id= "Sessionfactory"
Class= "Org.springframework.orm.hibernate5.annotation. Localsessionfactorybean ">
<!--Configure connection pooling--
<property name= "DataSource" ref= "DataSource"/>
<!--configuring annotation component Classes--
<!--
<property name= "Annotatedclasses" >
<list>
<value>com.s2sh.domain.User</value>
</list>
</property>
-
<!--automatically scan entity classes without writing a qualified name--
<property name= "Packagestoscan" >
<value>com.s2sh.domain</value>
</property>
<!--Hibernate main configuration file contents-
<property name= "Hibernateproperties" >
<props>
<prop key= "Hibernate.dialect" >org.hibernate.dialect.MySQLDialect</prop>
<prop key= "Hibernate.show_sql" >true</prop>
</props>
</property>
</bean>
8, Configuration hibernatetemplate:
<bean name= "Hibernatetemplate" class= "Org.springframework.orm.hibernate5.HibernateTemplate" >
<property name= "Sessionfactory" ref= "Sessionfactory" ></property>
</bean>
9. Hibernate transaction Manager:
<bean id= "Txmanager"
class= "Org.springframework.orm.hibernate5.HibernateTransactionManager" >
<property name= "Sessionfactory" ref= "Sessionfactory"/>
</bean>
10. Using the transaction manager:
<!--using Transaction Manager--
<tx:annotation-driven transaction-manager= "Txmanager"/>
11, in the need for transaction management business processing methods annotated @transactional;
12, Entity class User add @entity, @Id and other hibernate entity annotations;
13, SQL database Building table;
Note: When configuring Hibernate-related classes, the class to which the package is to be used is selected based on the version of Hibernate.
HIBERNATE5 primary key generation strategy with @generatedvalue (strategy=generationtype.identity).
This article for Bo Master original, allow reprint, but please declare the original address: http://www.coselding.cn/blog/8/8-151.html
SSH Framework Integration