spring3.1, hibernate4.1 配置备份,struts2.2.1,sitemesh 2.4.2
1. spring 配置(WEB-INF/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:aop="http://www.springframework.org/schema/aop" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"> <context:component-scan base-package="com.ice"> <context:include-filter type="regex" expression=".*.action.*" /> <context:include-filter type="regex" expression=".*.service.*" /> <context:include-filter type="regex" expression=".*.dao.*" /> </context:component-scan> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:resources.properties</value> </list> </property> </bean> <bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource"> <property name="driverClass" value="${connection.driver_class}" /> <property name="url" value="${connection.url}" /> <property name="username" value="${connection.username}" /> <property name="password" value="${connection.password}" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation" value="classpath:hibernate.cfg.xml" /> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <tx:advice id="baseServiceAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="get*" read-only="true" propagation="REQUIRED" /> <tx:method name="find*" read-only="true" propagation="REQUIRED" /> <tx:method name="save*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="remove*" propagation="REQUIRED" /> <tx:method name="add*" propagation="REQUIRED" /> <!--默认其他方法都是REQUIRED --> <tx:method name="*"/> </tx:attributes> </tx:advice> <aop:config proxy-target-class="true"> <aop:pointcut id="bussinessService" expression="execution(* com.ice.*.service.impl.*.*(..))" /> <aop:advisor pointcut-ref="bussinessService" advice-ref="baseServiceAdvice" /> </aop:config> <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basenames"> <list> <!-- i18n文件所在的位置 --> <value>i18n.labels</value> <value>i18n.messages</value> <value>i18n.errors</value> <value>i18n.db.labels</value> <value>i18n.db.messages</value> <value>i18n.db.errors</value> </list> </property> </bean> </beans>
2. Hibernate 配置(src/hibernate.cfg.xml)
<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <!-- Generated by MyEclipse Hibernate Tools. --> <hibernate-configuration> <session-factory> <property name="hibernate.dialect"> org.hibernate.dialect.MySQLDialect </property> <mapping class="com.ice.model.db.BsDbservers" /> </session-factory> </hibernate-configuration>
3. struts配置(src/struts.xml)
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> <struts> <constant name="struts.devMode" value="false" /> <!-- <constant name="struts.locale" value="zh_CN" /> --> <constant name="struts.ui.theme" value="simple"/> <constant name="struts.custom.i18n.resources" value="i18n/messages,i18n/labels,i18n/errors,i18n/db/messages,i18n/db/labels,i18n/db/errors" /> <constant name="struts.action.extension" value="do" /> <package name="struts-db" extends="struts-default"> <!-- <interceptors> --> <!-- <interceptor-stack name="myStack"> --> <!-- <interceptor-ref name="checkbox"> --> <!-- <param name="uncheckedValue">0</param> --> <!-- </interceptor-ref> --> <!-- <interceptor-ref name="defaultStack" /> --> <!-- </interceptor-stack> --> <!-- </interceptors> --> <!-- <default-interceptor-ref name="myStack" /> --> </package> <package name="index" extends="struts-default"> <action name="index" method="index" class="com.ice.db.action.DbAction"> <result name="index">./views/index.jsp </result> </action> </package> <package name="dbtools" extends="struts-db" namespace="/db"> <action name="*Action!*" method="{2}" class="com.ice.db.action.{1}Action"> <result name="init">../views/db/Init{1}.jsp </result> <result name="query">../views/db/Query{1}.jsp </result> <result name="edit">../views/db/Edit{1}.jsp </result> <result name="detail">../views/db/Detail{1}.jsp </result> </action> </package> </struts>
4. sitemesh配置(WEB-INF/decorators.xml)
<?xml version="1.0" encoding="UTF-8"?> <!-- defaultdir指定装饰器文件所在的路径 --> <decorators defaultdir="/layout"> <!--excludes结点则指定了哪些路径的请求不使用任何模板 --> <excludes> <pattern>/views/common/*.jsp</pattern> <pattern>/Views/index.jsp</pattern> </excludes> <!--decorator结点指定了模板的位置和文件名,通过pattern来指定哪些路径引用哪个模板 --> <decorator name="main" page="./layout.jsp"> <pattern>/*</pattern> </decorator> </decorators>
5. web.xml
<?xml version="1.0" encoding="UTF-8" ?> <web-app version="3.0" 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_3_0.xsd"> <display-name>xmgl</display-name> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <filter> <filter-name>LoginFilter</filter-name> <filter-class>com.ice.common.impl.LoginFilter</filter-class> <async-supported>true</async-supported> </filter> <filter> <filter-name>struts2Prepare</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter</filter-class> </filter> <filter> <filter-name>sitemesh</filter-name> <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class> </filter> <filter> <filter-name>struts2Execute</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>LoginFilter</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping> <filter-mapping> <filter-name>struts2Prepare</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping> <filter-mapping> <filter-name>sitemesh</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping> <filter-mapping> <filter-name>struts2Execute</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>