Struts + Hibernate + Spring Integration

Source: Internet
Author: User

For historical reasons, this is a small example of SSH integration left over last month. This section describes Spring configurations for each layer, Struts configurations, and several pages. Spring-common.xml, mainly configure transactions: [html] <? 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: tx =" http://www.springframework.org/schema/tx "Xmlns: aop =" http://www.springframework.org/schema/aop "Xsi: schemaLocation =" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans Spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx Spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop /Spring-aop-3.0.xsd "> <! -- Configure SessionFactory --> <bean id = "sessionFactory" class = "org. springframework. orm. hibernate3.LocalSessionFactoryBean "> <property name =" configLocation "> <value> classpath: hibernate. cfg. xml </value> </property> </bean> <! -- Configure the Transaction Manager --> <bean id = "transactionManager" class = "org. springframework. orm. hibernate3.HibernateTransactionManager "> <property name =" sessionFactory "> <ref bean =" sessionFactory "/> </property> </bean> <! --> <Aop: config> <aop: pointcut expression = "execution (* com. tgb. manager. *. *(..)) "id =" allManagerMethod "/> <aop: advisor advice-ref =" txAdvice "pointcut-ref =" allManagerMethod "/> </aop: config> <! -- Transaction propagation --> <tx: advice id = "txAdvice" transaction-manager = "transactionManager"> <tx: attributes> <tx: method name = "add *" propagation = "REQUIRED"/> <tx: method name = "del *" propagation = "REQUIRED"/> <tx: method name = "modify *" propagation = "REQUIRED"/> <tx: method name = "*" propagation = "REQUIRED" read-only = "true"/> </tx: attributes> </tx: advice> </beans> spring-daos.xml, configure the dao layer class: [html] <? Xml version = "1.0" encoding = "UTF-8"?> <Beans xmlns =" http://www.springframework.org/schema/beans "Xmlns: xsi =" http://www.w3.org/2001/XMLSchema-instance "Xsi: schemaLocation =" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans /Spring-beans-3.0.xsd "> <bean id =" userDao "class =" com. tgb. dao. userDaoImpl "> <property name =" sessionFactory "ref =" sessionFactory "/> </bean> </beans> spring-managers.xml, configure the manager layer class: [html] <? Xml version = "1.0" encoding = "UTF-8"?> <Beans xmlns =" http://www.springframework.org/schema/beans "Xmlns: xsi =" http://www.w3.org/2001/XMLSchema-instance "Xsi: schemaLocation =" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans /Spring-beans-3.0.xsd "> <bean id =" userManager "class =" com. tgb. manager. userManagerImpl "> <property name =" userDao "ref =" userDao "/> </bean> </beans> spring-actions.xml, configure the action layer class: [java] <? Xml version = "1.0" encoding = "UTF-8"?> <Beans xmlns =" http://www.springframework.org/schema/beans "Xmlns: xsi =" http://www.w3.org/2001/XMLSchema-instance "Xsi: schemaLocation =" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans /Spring-beans-3.0.xsd "> <bean name ="/user "class =" com. tgb. web. userAction "> <property name =" userManager "ref =" userManager "/> </bean> </beans> struts-config.xml, Struts configuration, some jump information, etc: [html] <? Xml version = "1.0" encoding = "UTF-8"?> <! DOCTYPE struts-config PUBLIC "-// Apache Software Foundation // DTD Struts Configuration 1.2 // EN "" http://struts.apache.org/dtds/struts-config_1_2.dtd "> <! -- ActionMapping configuration, set to request --> <struts-config> <form-beans> <form-bean name = "userForm" type = "com. tgb. web. userActionForm "/> </form-beans> <action-mappings> <action path ="/user "type =" org. springframework. web. struts. delegatingActionProxy "name =" userForm "scope =" request "> <forward name =" success "path ="/success. jsp "> </forward> </action-mappings> </struts-config> web. xml: configuration to be loaded when the web Container starts: [htm L] <? Xml version = "1.0" encoding = "UTF-8"?> <Web-app version = "2.4" xmlns =" http://java.sun.com/xml/ns/j2ee "Xmlns: xsi =" http://www.w3.org/2001/XMLSchema-instance "Xsi: schemaLocation =" http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee /Web-app_2_4.xsd "> <! -- Configure ActionServlet and central controller --> <servlet-name> action </servlet-name> <servlet-class> org. apache. struts. action. actionServlet </servlet-class> <init-param> <param-name> config </param-name> <param-value>/WEB-INF/struts-config.xml </param-value> </init-param> <param-name> debug </param-name> <param-value> 2 </param-value> </init-param> <init-param> <param-name> detail </param-name> <param-valu E> 2 </param-value> </init-param> <load-on-startup> 2 </load-on-startup> </servlet> <servlet-mapping> <servlet-name> action </servlet-name> <url-pattern> *. do </url-pattern> </servlet-mapping> <context-param> <param-name> contextConfigLocation </param-name> <param-value> classpath: spring -*. xml </param-value> </context-param> <! -- Add a listener and load it when the web Container starts --> <listener-class> org. springframework. web. context. contextLoaderListener </listener-class> </listener> <filter-name> CharacterEncodingFilter </filter-name> <filter-class> org. springframework. web. filter. characterEncodingFilter </filter-class> <init-param> <param-name> encoding </param-name> <param-value> GB18030 </param-value> </init- param> </filter> <filter-mapping> <Filter-name> CharacterEncodingFilter </filter-name> <url-pattern> *. do </url-pattern> </filter-mapping> <! -- Manage sessions --> <filter-name> OpenSessionInViewFilter </filter-name> <filter-class> org. springframework. orm. hibernate3.support. openSessionInViewFilter </filter-class> </filter> <filter-mapping> <filter-name> OpenSessionInViewFilter </filter-name> <url-pattern>/* </url-pattern> </filter-mapping> </web-app> page: index. jsp [html] <% @ page pageEncoding = "UTF-8" contentType = "text/html; charset = UTF-8" %> <Html>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.