qq_慕姐8173930
2016-09-27 10:04
开发用的集成环境是intelliJ Idea,课程中引到lib中的jar包全是用maven依赖引进来的,但是这节课中的com.springsource.org.aopalliance和aspectj.weaver
都会报错。
意思很明显啊 你这个事务通知标签中没有transaction-manager这个属性。你把它的schema加上,看有没有提示,一般有提示,就不会出错。
楼主,我把tx的命名空间和标签连接加进去了,但是有出现了无法发现元素tx:advice 的异常,具体如下:
Caused by: org.xml.sax.SAXParseException; lineNumber: 47; columnNumber: 71; cvc-complex-type.2.4.c: 通配符的匹配很全面, 但无法找到元素 'tx:advice' 的声明。
下面是我的spring-config.xml配置文件:
<?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:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xcd
">
<!--使用自动装配配置,可以省略定义业务层类accountService的bean-->
<!--<context:component-scan base-package="com.test.spring.transaction"/>-->
<!--引入外部属性文件-->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!--配置c3p0连接池-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driverClass}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<!--配置业务层类-->
<bean id="accountService" class="com.spring.transaction.declarative.serviceImpl.AccountServiceImpl2">
<!--<property name="accountDao" ref="accountDao"/>-->
</bean>
<!--配置dao类,注入c3p0连接池,为dao类加入jdbcTemplate-->
<bean id="accountDao2" class="com.spring.transaction.declarative.daoImpl.AccountDaoImpl">
<property name="dataSource" ref="dataSource"/>
</bean>
<!--配置事务管理器-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!--配置事务的增强,通过配置通知(advice)-->
<!--todo 出现tx:advice未被声明的异常?-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="transfer" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<!--配置切面-->
<aop:config>
<aop:pointcut id="pointcut1" expression="execution(* com.spring.transaction.declarative.serviceImpl.AccountServiceImpl2.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut1"/>
</aop:config>
</beans>
请问是怎么解决的啊
Spring事务管理
87322 学习 · 205 问题
相似问题
回答 1