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

推荐订阅源

cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Engineering at Meta
Engineering at Meta
U
Unit 42
阮一峰的网络日志
阮一峰的网络日志
The Register - Security
The Register - Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Blog — PlanetScale
Blog — PlanetScale
C
Check Point Blog
博客园_首页
云风的 BLOG
云风的 BLOG
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Hugging Face - Blog
Hugging Face - Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The GitHub Blog
The GitHub Blog
L
LangChain Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 【当耐特】
博客园 - Franky
Cyberwarzone
Cyberwarzone
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cisco Blogs
T
Tailwind CSS Blog
Project Zero
Project Zero
博客园 - 叶小钗
S
SegmentFault 最新的问题
K
Kaspersky official blog
B
Blog
T
The Exploit Database - CXSecurity.com
A
About on SuperTechFans
Google DeepMind News
Google DeepMind News
B
Blog RSS Feed
G
Google Developers Blog
Security Latest
Security Latest
T
Tenable Blog
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
H
Help Net Security
T
Threat Research - Cisco Blogs
美团技术团队
AWS News Blog
AWS News Blog
P
Proofpoint News Feed
F
Fortinet All Blogs
NISL@THU
NISL@THU
大猫的无限游戏
大猫的无限游戏
The Last Watchdog
The Last Watchdog
Simon Willison's Weblog
Simon Willison's Weblog
G
GRAHAM CLULEY
D
DataBreaches.Net

博客园 - 山里人家

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" ?>

<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
   
<struts>
      <constant name="struts.objectFactory" value="spring"></constant>

      <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)