<?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.5.xsd

           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd

           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

   

    <!-- 初始化SessionFactory,读取hibernate配置文件,

    如果hibernate的映射关系是通过Annotation注解形式完成,SessionFactoryclass如下面的bean中的class,

    如果是XXX.hbm.xml形式,SessionFactory就应该交给"org.springframework.orm.hibernate3.LocalSessionFactoryBean"管理 -->

    <bean id="sessionFactory"

    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">

       <property name="configLocation"

           value="classpath:hibernate.cfg.xml">

       </property>

    </bean>

   

    <!-- 初始化HibernateTemplate,SessionFactory注入到HibernateTemplate -->

    <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">

       <property name="sessionFactory" ref="sessionFactory"></property>

    </bean>

 

   

    <bean id="user" class="com.s2sh.domain.User" />

    <!-- HibernateTemplate模版注入到持久层 -->

    <bean id="userDao" class="com.s2sh.dao.UserDAO">

       <!--<property name="sessionFactory" ref="sessionFactory"></property>-->

       <property name="hibernateTemplate" ref="hibernateTemplate"></property>

    </bean>

 

    <bean id="userBiz" class="com.s2sh.biz.UserBiz">

       <property name="userdao" ref="userDao"></property>

    </bean>

 

    <!-- 初始化action,Struts2Struts1action初始化方法不同,

    Struts1初始化的方法是beanname属性定义为"/userAction",

    然后在struts-config.xml,通过name属性找到匹配的action,

    注意:struts1的配置文件中,action就必须交给spring的代理类来管理:

     "org.springframework.web.struts.DelegatingActionProxy"-->

    <bean id="userAction" class="com.s2sh.action.UserAction">

       <property name="userBiz" ref="userBiz"></property>

       <property name="user" ref="user"></property>

    </bean>

 

 

    <bean id="transactionManager"

        class="org.springframework.orm.hibernate3.HibernateTransactionManager">

       <property name="sessionFactory" ref="sessionFactory"></property>

    </bean>

 

    <!-- aop -->

    <aop:config>

       <aop:pointcut expression="execution(public * com.s2sh.biz.*.*(..))" id="cut"/>

       <aop:advisor advice-ref="advice" pointcut-ref="cut"/>

    </aop:config>

    <tx:advice id="advice" transaction-manager="transactionManager">

       <tx:attributes>

           <tx:method name="*"/>

       </tx:attributes>

    </tx:advice>

 

</beans>