开发者社区> 问答> 正文

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

展开
收起
爱吃鱼的程序员 2020-06-23 01:41:32 495 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB
    <?xmlversion="1.0"encoding="UTF-8"?><beansxmlns="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/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.0.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-3.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsd"><!--配置数据源--><beanid="dataSource"class="org.springframework.jdbc.datasource.DriverManagerDataSource"><propertyname="driverClassName"value="com.mysql.jdbc.Driver"/><propertyname="url"value="jdbc:mysql://localhost:3306/test"/><propertyname="username"value="root"/><propertyname="password"value="christmas258@"/></bean><!--配置一个JdbcTemplate实例,并将这个“共享的”,“安全的”实例注入到不同的DAO类中去--><beanid="jdbcTemplate"class="org.springframework.jdbc.core.JdbcTemplate"><propertyname="dataSource"ref="dataSource"/></bean><!--声明事务管理器--><beanid="txManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><propertyname="dataSource"ref="dataSource"/></bean><!--需要实施事务增强的目标业务Bean--><beanid="libraryTarget"class="com.mucfc.dao.LibraryDaoImpl"p:jdbcTemplate-ref="jdbcTemplate"/><!--使用tx/aop来配置--><aop:config><!--通过aop定义事务增强切面--><aop:pointcutid="serviceMethod"expression="execution(*com.mucfc.dao.LibraryDaoImpl.*(..))"/><!--引用事务增强--><aop:advisorpointcut-ref="serviceMethod"advice-ref="txAdvice"/></aop:config><!--事务增强--><tx:adviceid="txAdvice"transaction-manager="txManager"><!--事务属性定义--><tx:attributes><tx:methodname="get*"read-only="false"/><tx:methodname="add*"rollback-for="Exception"/><tx:methodname="del*"/></tx:attributes></tx:advice>

    destroy-method="close"
    p:driverClassName="com.mysql.jdbc.Driver"
    p:url="jdbc:mysql://localhost:3309/sampledb"
    p:username="root"
    p:password="0000"/>测试一下,去掉一个试试

    2020-06-23 01:41:48
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关课程

更多

相关电子书

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