tx:advice的聲明
我把tx的命名空間和標(biāo)簽連接加進去了,但是有出現(xiàn)了無法發(fā)現(xiàn)元素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 "> ????<!--使用自動裝配配置,可以省略定義業(yè)務(wù)層類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> ????<!--配置業(yè)務(wù)層類--> ????<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> ????<!--配置事務(wù)管理器--> ????<bean?id="transactionManager"?class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> ????????<property?name="dataSource"?ref="dataSource"/> ????</bean> ????<!--配置事務(wù)的增強,通過配置通知(advice)--> ????<!--todo?出現(xiàn)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的相關(guān)jar包都是4.3版本的,使用的idea編譯器,編譯時沒有異常。
2017-12-17
xmlns:tx="
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd