Y_Bei 2015-10-28 16:29 采纳率: 25%
浏览 2830

javaweb 在配application.xml报错,tx跟aop无法识别

新建web工程报错The matching wildcard is strict, but no declaration can be found for element 'tx:advic

<?xml version="1.0" encoding="UTF-8"?>

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
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-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">

<!-- 扫描类包,将标注Spring注解的类自动转化为Bean,同时完成Bean的注入 -->
<context:component-scan base-package="com.KJ.dao"/>
<!-- 扫描类包,将标注Spring注解的类自动转化为Bean,同时完成Bean的注入 -->
<context:component-scan base-package="com.KJ.service"/>

<!-- 定义一个使用DBCP实现的数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" 
      destroy-method="close"
      p:driverClassName="com.mysql.jdbc.Driver"
      p:url="jdbc:mysql://localhost:3309/sampledb"
      p:username="root"
      p:password="0000"/>

<!-- 定义一个Jdbc模板Bean -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"
      p:dataSource-ref="dataSource"/>

<!-- 配置事物管理器 -->    
<bean id="transactionManager"
      class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
      p:dataSource-ref="dataSource"/>

<tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
        <tx:method name="*"/>
    </tx:attributes>
</tx:advice>
<aop:config proxy-target-class="true">
    <aop:pointcut id="serviceMethod"
         expression="execution(* com.KJ.service.*.*(..))"/>
    <aop:advisor pointcut-ref="serviceMethod" advice-ref="txAdvice"/>
</aop:config>

用eclipse luna 新建web,在配的时候报错了,但是在老师的项目中却没有报错,這是为何?还有哪里没有考虑到的

  • 写回答

2条回答 默认 最新

  • Evankaka 博客专家认证 2015-10-29 00:41
    关注
     <?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:p="http://www.springframework.org/schema/p"  
        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.0.xsd    
               http://www.springframework.org/schema/tx    
               http://www.springframework.org/schema/tx/spring-tx-3.0.xsd  
               http://www.springframework.org/schema/aop    
               http://www.springframework.org/schema/aop/spring-aop-3.0.xsd  
               http://www.springframework.org/schema/context    
               http://www.springframework.org/schema/context/spring-context-3.0.xsd">  
        <!-- 配置数据源 -->  
        <bean id="dataSource"  
            class="org.springframework.jdbc.datasource.DriverManagerDataSource">  
            <property name="driverClassName" value="com.mysql.jdbc.Driver" />  
            <property name="url" value="jdbc:mysql://localhost:3306/test" />  
            <property name="username" value="root" />  
            <property name="password" value="christmas258@" />  
        </bean>  
        <!--配置一个JdbcTemplate实例,并将这个“共享的”,“安全的”实例注入到不同的DAO类中去 -->  
        <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">  
            <property name="dataSource" ref="dataSource" />  
        </bean>  
        <!-- 声明事务管理器 -->  
        <bean id="txManager"  
            class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  
            <property name="dataSource" ref="dataSource" />  
        </bean>  
        <!-- 需要实施事务增强的目标业务Bean -->  
        <bean id="libraryTarget" class="com.mucfc.dao.LibraryDaoImpl"  
            p:jdbcTemplate-ref="jdbcTemplate" />  
    
        <!-- 使用tx/aop来配置 -->  
        <aop:config>  
            <!-- 通过aop定义事务增强切面 -->  
            <aop:pointcut id="serviceMethod"  
                expression="execution(* com.mucfc.dao.LibraryDaoImpl.*(..))" />  
            <!-- 引用事务增强 -->  
            <aop:advisor pointcut-ref="serviceMethod" advice-ref="txAdvice" />  
        </aop:config>  
    
        <!--事务增强 -->  
        <tx:advice id="txAdvice" transaction-manager="txManager">  
            <!-- 事务属性定义 -->  
            <tx:attributes>  
                <tx:method name="get*" read-only="false" />  
                <tx:method name="add*" rollback-for="Exception" />  
                <tx:method name="del*" />  
            </tx:attributes>  
        </tx:advice>
    
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!