在SpringMVC的配置文件中<mvc:annotation-driven />应该写在哪个配置文件中
展开全部
在bean.xml中进行定义的,主要是为了说明那些类方法使用事物。
如:<tx:annotation-driven transaction-manager="transactionManager" />。
举例:
<?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:context="http://www.springframework.org/schema/context"
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/context
http://www.springframework.org/schema/context/spring-context-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">
<bean id="service" class="com.bluedot.bookAdministrate.service.FindService">
<property name="dao" ref="dao"></property>
</bean>
<bean id="dao" class="com.bluedot.bookAdministrate.dao.FindDao">
<property name="hibernateTemplate" ref="hibernateTemplate"></property>
</bean>
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>classpath:jdbc.properties</value>
</property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="mySessionFactory"></property>
</bean>
<bean id="myDataSource" destroy-method="close"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${driverClassName}" />
<property name="url" value="${url}" ></property>
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<bean id="mySessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- 使用数据源 -->
<property name="dataSource" ref="myDataSource" />
<!-- 设置实体对象映射文件 -->
<property name="mappingResources">
<list>
<value>com/bluedot/bookAdministrate/entity/BorrowBooks.hbm.xml</value>
<value>com/bluedot/bookAdministrate/entity/Books.hbm.xml</value>
<!-- <value>com/bluedot/bookAdministrate/entity/UserList.hbm.xml</value> -->
</list>
</property>
<!-- 设置hibernate的配置信息 -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="mySessionFactory"></property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<tx:advice id="txAd" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" read-only="true" />
<tx:method name="*" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut expression="execution(public * com.bluedot.bookAdministrate.service.*.*(..))"
id="myPonitcut1" />
<aop:advisor advice-ref="txAd" pointcut-ref="myPonitcut1" />
</aop:config>
</beans>
如:<tx:annotation-driven transaction-manager="transactionManager" />。
举例:
<?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:context="http://www.springframework.org/schema/context"
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/context
http://www.springframework.org/schema/context/spring-context-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">
<bean id="service" class="com.bluedot.bookAdministrate.service.FindService">
<property name="dao" ref="dao"></property>
</bean>
<bean id="dao" class="com.bluedot.bookAdministrate.dao.FindDao">
<property name="hibernateTemplate" ref="hibernateTemplate"></property>
</bean>
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>classpath:jdbc.properties</value>
</property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="mySessionFactory"></property>
</bean>
<bean id="myDataSource" destroy-method="close"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${driverClassName}" />
<property name="url" value="${url}" ></property>
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<bean id="mySessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- 使用数据源 -->
<property name="dataSource" ref="myDataSource" />
<!-- 设置实体对象映射文件 -->
<property name="mappingResources">
<list>
<value>com/bluedot/bookAdministrate/entity/BorrowBooks.hbm.xml</value>
<value>com/bluedot/bookAdministrate/entity/Books.hbm.xml</value>
<!-- <value>com/bluedot/bookAdministrate/entity/UserList.hbm.xml</value> -->
</list>
</property>
<!-- 设置hibernate的配置信息 -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="mySessionFactory"></property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<tx:advice id="txAd" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" read-only="true" />
<tx:method name="*" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut expression="execution(public * com.bluedot.bookAdministrate.service.*.*(..))"
id="myPonitcut1" />
<aop:advisor advice-ref="txAd" pointcut-ref="myPonitcut1" />
</aop:config>
</beans>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询