Spring的多模块配置

来源:互联网 发布:兄弟打印机扫描软件 编辑:程序博客网 时间:2024/05/17 00:57

web.xml文件中:
<context-param>
   <param-name>contextConfigLocation</param-name>
     <param-value>/WEB-INF/classes/applicationContext.xml,/WEB-INF/classes/applicationContext-*.xml</param-value>
</context-param>

同样还有别的方式配置

比如在struts文件中配置:

比如在主配置文件中通过import子文件来配置:

<import resource="applicationContext-dao.xml"/>
<import resource="applicationContext-service.xml"/>
<import resource="applicationContext-action.xml"/>

在主配置文件中配置共同的东西,applicationContext.xml
<beans ...... >

<context:annotation-config />
<aop:aspectj-autoproxy />
    
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
   <property name="configLocation" value="classpath:hibernate.cfg.xml" />
</bean>

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
     <property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>

<bean id="txBase" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" lazy-init="true" abstract="true">
     <!--
为事务模板注入事务管理器
-->
     <property name="transactionManager"><ref bean="transactionManager"/></property>
     <!--
设置事务属性
-->
     <property name="transactionAttributes">
         <props>
             <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
             <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
             <prop key="new*">PROPAGATION_REQUIRED</prop>
             <prop key="add*">PROPAGATION_REQUIRED</prop>
             <prop key="del*">PROPAGATION_REQUIRED</prop>
             <prop key="mod*">PROPAGATION_REQUIRED</prop>
         </props>
     </property>
</bean>

<bean id="sAspect" class="com.william61.littleStore.base.SystemAspect" />
<aop:config>
   <aop:pointcut id="dataAccessOperation" expression="execution(* com.william61.littleStore.dao.*.*(..))" />
   <aop:aspect id="afterThrowingExample" ref="sAspect">   
    <aop:after-throwing pointcut-ref="dataAccessOperation" throwing="ex" method="dataAccessException" />
   </aop:aspect>
</aop:config>   
   
</beans>

在子配置文件中

<bean id="UserDAO" parent="txBase" >
     <property name="target">
         <bean class="com.william61.littleStore.dao.impl.hbt.authority.UserDaoImpl">
             <property name="sessionFactory" ref="sessionFactory" />
             <!-- <property name="sessionFactory"><ref local="sessionFactory"/></property>
如果是这样会出错的
-->
         </bean>   
     </property>
</bean>

 

原创粉丝点击