Struts2+spring+hibernate configuration file Configuration __struts2

Source: Internet
Author: User
Tags aop configuration settings ssh
struts2+spirng+hibernate configuration file-document

New stickers:

Statement: This is my Java training in the learning phase of the configuration file does not use the real development of the environment, can only be used for learning and reference.

The focus of this article is on the configuration of applicationcontext.xml files.

If there is a wrong place, please leave a message to inform, thank you! directory required jar package Web configuration file Applicationcontext.xml profile setting Struts profile configuration entity class mapping file configuration jar Package

The different versions of the jar may affect the address of the class file referenced by the profile, and I will point it out to the application configuration. configuration of Web files

Web configuration file:

<?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 "> <!--struts2 filter--> <filter> <filter-na Me>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> <!--Spring Listener--> <listener&
        Gt <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </ Listener> <!--set Applicationcontext.xml profile location Classpath: Representative src--> <context-param> <par Am-name>contextconfiglocation</paraM-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> ;! --Configure Request filter, encoding format for UTF-8, avoid Chinese garbled--> <filter> <filter-name>springutf8encoding</filter-name&gt  
       ; <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param&  
           Gt <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init -param> <init-param> <param-name>forceEncoding</param-name> <pa  
       ram-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>springUtf8Encoding</filter-name> <url-pattern>/*</url-pattern> &L T;/filter-mapping> <welcome-file-list> <welcome-file>login.jsp</welcome-file> &Lt;/welcome-file-list> </web-app>
 
application configuration file configuration

Applicationcontext.xml file

<?xml version= "1.0" encoding= "UTF-8"?> <!--beans header files are corresponding except for http://www.w3.org/2001/XMLSchema-instance The other four correspond to the following xsi:schemalocation, one corresponding to the two--> <beans xmlns= "Http://www.springframework.org/schema/beans" xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" xmlns:tx= " Http://www.springframework.org/schema/tx "xmlns:context=" Http://www.springframework.org/schema/context "Xsi:sche malocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/
                           Beans/spring-beans.xsd Http://www.springframework.org/schema/context Http://www.springframework.org/schema/context/spring-context-4.1.xsd Http://www.springframewor
                           K.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/spring-aop-4.1.xsd Http://www.springframework.Org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd "> <!--data source There is no connection pool configuration, the Internet can search out a lot of--> <bean id= "DataSource" class= "Org.apache.commons.dbcp.BasicDataSource" > ;p roperty name= "Driverclassname" value= "Com.mysql.jdbc.Driver"/> <property name= "url" value= "jdbc:mysql://l Ocalhost:3306/test?useunicode=true&amp;characterencoding=utf-8 "/> <property name=" username "value=" root "/> <property name=" password value= "root"/> </bean> <!--2. Database connection Project--> <be An id= "sessionfactory" class= "Org.springframework.orm.hibernate3.LocalSessionFactoryBean" > <property name= "D
                Atasource "ref=" DataSource "/> <property name=" mappingresources "> <list> <value>com/ssh/entity/User.hbm.xml</value> </list> </property> <p Roperty name= "HibernatepRoperties "> <props> <prop key=" Hibernate.dialect ">org.hibernate.dialect.mysq   
        ldialect</prop> <prop key= "Hibernate.show_sql" >true</prop> </props> </property> </bean> <!--Spring Management 3 Chunk--> <!--1. Incorporate sessionfactory into Spring tube  
       Daniel--> <bean name= "Txmanager" class= "Org.springframework.orm.hibernate3.HibernateTransactionManager" > <property name= "Sessionfactory" ref= "sessionfactory" ></property> </bean> <!--2 settings monitored bit Place Aop--> <aop:config> <aop:pointcut id= "Bussinessservice expression=" Execution (public * com.ssh. Biz.*.* (..)) " /> <aop:advisor pointcut-ref= "Bussinessservice" advice-ref= "Txadvice"/> </aop:config> &l t;! --3 Transaction configuration settings 3.1 method name constraint 3.2 setting is read-only 3.3 set transaction's policy 3.4 set the isolation level of the transaction--> <tx:advice id= "Txadvice" Transaction-ma Nager= "TXmanager "> <tx:attributes> <tx:method name=" add* "read-only=" true "propagation=" REQUIRED "
            isolation= "DEFAULT"/> <tx:method name= "update*" read-only= "true" propagation= "REQUIRED"/> <tx:method name= "delete*" read-only= "true" propagation= "REQUIRED"/> </tx:attributes> </tx:a Dvice> <!--custom class injection (registration)--> <!--DAO--> <bean id= "Userdaoimpl" class= "Com.ssh.daoImpl.Us" Erdaoimpl "> <property name=" sessionfactory "ref=" Sessionfactory "/> </bean> <!--biz--&
    Gt <bean id= "Userbizimpl" class= "Com.ssh.bizImpl.UserBizImpl" > <property name= "Userdaoimpl" ref= "Userdaoimpl" "></property> </bean> <!--action--> <bean id=" loginaction "class=" Com.ssh.action.Lo Ginaction "> <property name=" Userbizimpl "ref=" Userbizimpl "></property> </bean> </beans >

The red Place is the jar is different, will cause the package path different
Struts2 configuration file Configuration

Struts.xml

<?xml version= "1.0" encoding= "UTF-8"?> <!
DOCTYPE struts public
    "-//apache Software foundation//dtd struts Configuration 2.0//en"
    "http:// Struts.apache.org/dtds/struts-2.0.dtd ">

<struts>

        <!--open Development mode-->
<constant name=" Struts.devmode "value=" true "/>
    <!--remarriage agreement     This is an important part of spring and struts connections-->
    <constant name=" Struts.objectfactory "value=" Spring "/> 

    <package name=" Login "extends=" Struts-default ">
        < Action name= "loginaction" class= "loginaction" method= "Checklogin" >
            <result name= "Success" >/main.jsp </result>
            <result name= "Login" >/login.jsp</result>
        </action>
    </ Package>

</struts>
configuration of Entity class mapping files

User.hbm.xml

<?xml version= "1.0"?>
<! DOCTYPE hibernate-mapping public 
    "-//hibernate/hibernate mapping DTD 3.0//en"
    "http:// Hibernate.sourceforge.net/hibernate-mapping-3.0.dtd ">

    <!--package is the package path where the mapping file is located  -->
< Hibernate-mapping package= "Com.ssh.entity" >

<!--name is the entity class name     table is the name of the corresponding table-->
    <class name= " User ' table= ' >
    <!--name is the entity class's property      column is the database field-->
        <id name= "id" column= "id" type= " Java.lang.Integer ">
            <generator class=" native "/>
        </id>

        <property name=" username " column= "username" type= "java.lang.String"/> <property name= "password" column= "password"
        Java.lang.String "/>
    </class>

Summarize:
The configuration of the SSH framework is difficult on the configuration of spring, where the spring configuration is just the most basic configuration. Some of the default configurations and some configurations that are not applicable in learning are omitted.

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.