问题描述
- 有人可以解决一下关于“ 通配符的匹配很全面, 但无法找到元素 'tx:advice' 的声明”的问题
-
xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" 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-3.1.xsd http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.springframework.org/schema/aop/spring-aop-3.1.xsd"> <!--配置sessionFactory 将数据源注入,并设置hibernate的基本配置 --> <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/hiber_first"></property> <property name="username" value="root"></property> <property name="password" value="chen007"></property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="dataSource" ref="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.hbm2ddl.auto">update</prop> </props> </property> <!-- 配置映射文件, --> <property name="mappingResources" value="cn/cc/vo/Person.hbm.xml"/> </bean> <!--将SessionFactory 注入DAO,拥有sessionFactory容器后才容易进行presistent操作 --> <bean id="userDao" class="cn.cc.springIntergratingHibernate.IUserDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!--设置事务管理,需要注入sessionFactory --> <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> <!--配置事务增强处理器 --> </bean> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> 所有以get开头的方法只有只读权限 <tx:method name="get*" read-only="true"/> 其他方法使用默认设置 <tx:method name="*"/> </tx:attributes> </tx:advice> <aop:config> <!--指定在IUserDao切入点 使用txAdvice事务增强处理--> <aop:pointcut expression="bean(IUserDao)" id="userPointcut"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="userPointcut"/> </aop:config> <!--配置事务拦截器 transactionInterceptor,需要注入TransactionManager --> <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"> <!--为事务拦截器注入一个管理器 --> <property name="transactionManager" ref="transactionManager"></property> <property name="transactionAttributes"> <!--定义事务传播属性 --> <props> <prop key="save">PROPAGATION_REQUIRED</prop> <prop key="delete">PROPAGATION_REQUIRED</prop> <prop key="check">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <!--定义BeanNameAutoProxyCreator代理,自动创建相关bean --> <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <!--指定哪些bean自动生成代理 --> <property name="beanNames"> <list> <value>userDao</value> </list> </property> <property name="interceptorNames"> <list> <value>transactionInterceptor</value> </list> </property> </bean> </beans>
可以看出来nameSpace已经导入了相关的应用了,但还是找不到
解决方案
xsi:schemaLocation 加上:
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
时间: 2024-10-03 15:28:34