惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 山里人家

PHP魔术函数集锦 gbk gb2312 utf8区别 - 山里人家 适合初学者,用MyEclipse编写第一个j2me MyEclipse开发手机程序-安装开发环境(图解) - 山里人家 - 博客园 javascript 常用语法词典 - 山里人家 - 博客园 电脑高手最常用的5个按钮! 汇总Eclipse快捷键 myeclipse7汉化 struts2通过拦截器实现用户权限验证 struts2 ognl 与 jsp2.1 el 的冲突问题 STRUTS2 ACTION的跳转类型说明 JXL读取EXCEL STRUTS 2之 标签 - 山里人家 myeclipse 快捷键 - 山里人家 STRUTS2 ACTION的扩展名修改方法 ASP.NET网络编程中经常用到的27个函数集 Asp.Net细节性问题技巧精萃 DIV确认对话框 JXL包使用 - 山里人家
S2SH配置 - 山里人家 - 博客园
山里人家 · 2009-02-12 · via 博客园 - 山里人家

配置方法1:

***********************************web.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">

<context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath*:applicationContext-*.xml,/WEB-INF/applicationContext*.xml</param-value>
</context-param>

<listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

      <filter>
     <filter-name>lazyLoadingFilter</filter-name>
     <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter>  
        <filter-name>s2</filter-name>  
        <filter-class>  
            org.apache.struts2.dispatcher.FilterDispatcher  
        </filter-class>  
    </filter>  

         <filter-mapping>
     <filter-name>lazyLoadingFilter</filter-name>
     <url-pattern>*.action</url-pattern>
     </filter-mapping>

        <filter-mapping>  
        <filter-name>s2</filter-name>  
        <url-pattern>/*</url-pattern>  
    </filter-mapping>  

            <!--
<filter>
    <filter-name>Spring character encoding filter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
    <param-name>encoding</param-name>
    <param-value>GBK</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>Spring character encoding filter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
    -->
<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

</web-app>

**************************aplicationContext-common.xml*****************************

        <prop key="hibernate.show_sql">true</prop>    <!--显示SQL语句-->
          <prop key="hibernate.format_sql">true</prop>
    </props>
   </property>
   <property name="mappingResources">
     <list>
         <value>com/bcm/model/Author.hbm.xml</value>
     </list>
   </property>
</bean>

  

   <!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
   <property name="sessionFactory">
    <ref bean="sessionFactory"/>
   </property>
</bean>

<!-- 配置事务的传播特性 -->
<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="*" read-only="true"/>
   </tx:attributes>
</tx:advice>

<!-- 那些类的哪些方法参与事务 -->
<aop:config>
   <aop:pointcut id="allManagerMethod" expression="execution(*

com.bcm.service.impl.*.*(..))"/>
   <aop:advisor pointcut-ref="allManagerMethod" advice-ref="txAdvice"/>
</aop:config>
</beans>

**************************aplicationContext-bean.xml*****************************

**************************aplicationContext-action.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:tx="http://www.springframework.org/schema/tx"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">

<!-- 此处的id="addAction" 必须与struts.xml中class="addAction"相一致-->
     <bean id="addAction" class="com.bcm.action.AuthorAction" scope="prototype">
          <property name="authorservice" ref="AuthorServiceImpl"></property>
     </bean>

    </beans>

*************************struts.xml*****************************

<?xml version="1.0" encoding="UTF-8" ?>

   

   <constant name="struts.i18n.encoding" value="gbk"></constant>
      <package name="struts2" extends="struts-default">

             <action name="add" class="

addAction" method="add">
         <result>index.jsp</result>
      </action>

      <action name="log" class="logAction" method="add">
        <result type="redirect-action">list.action</result>
      </action>

              <action name="list" class="listAction" method="list">
        <result>list.jsp</result>
      </action>

               </package>
</struts>

备注:aplicationContext.xml文件 最好分为几个 如:

     *   aplicationContext-common.xml (用于配置事务,数据源...)

     *    aplicationContext-bean.xml(用于配置普通的类)

     *    aplicationContext-action.xml(用于配置action)

配置方法2:将aplicationContext-common.xml 中的数据库配置交给hibernate.cfg.xml 。 修改如下:

*****************************************aplicationContext-common.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:tx="
http://www.springframework.org/schema/tx"
      xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-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/spring_hibernate_1?characterEncoding=utf-8"></property>
        <property name="username" value="root"></property>
        <property name="password" value="root"></property>
    </bean>

        <bean id="sessionFactory"
   class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
   <property name="dataSource">
     <ref bean="dataSource"/>
   </property>
   <property name="hibernateProperties">
    <props>
       <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
       <prop key="hibernate.show_sql">true</prop>  
             <prop key="hibernate.format_sql">true</prop>
    </props>
   </property>

      <property name="mappingResources">
     <list>
         <value>com/bcm/model/Author.hbm.xml</value>
     </list>
   </property>
</bean>
-->

   <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
   <property name="configLocation">
    <value>classpath:hibernate.cfg.xml</value>
   </property>
</bean>

      <!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
   <property name="sessionFactory">
    <ref bean="sessionFactory"/>
   </property>
</bean>

<!-- 配置事务的传播特性 -->
<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="*" read-only="true"/>
   </tx:attributes>
</tx:advice>

<!-- 那些类的哪些方法参与事务 -->
<aop:config>
   <aop:pointcut id="allManagerMethod" expression="execution(* com.bcm.service.impl.*.*(..))"/>
   <aop:advisor pointcut-ref="allManagerMethod" advice-ref="txAdvice"/>
</aop:config>
</beans>

*********************************** hibernate.cfg.xml   ********************************

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"
http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
   <property name="hibernate.connection.url">jdbc:mysql://localhost/spring_hibernate_1?characterEncoding=utf-8</property>
   <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
   <property name="hibernate.connection.username">root</property>
   <property name="hibernate.connection.password">root</property>
   <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
   <property name="hibernate.show_sql">true</property>
   <mapping resource="com/bcm/model/Author.hbm.xml"/>
</session-factory>
</hibernate-configuration>

注:所有的配置文件都在src目录下(除了web,xml)