开发者社区> 问答> 正文

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,在配的时候报错了,但是在老师的项目中却没有报错,這是为何?

展开
收起
蛮大人123 2016-03-20 11:00:49 3564 0
1 条回答
写回答
取消 提交回答
  • 我说我不帅他们就打我,还说我虚伪
    <?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>
    2019-07-17 19:09:07
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关课程

更多

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载