今天做一个S2SH项目的练习,配置SpringContext.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"
<span style="color:#FF0000;"> xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"</span>
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
<span style="color:#FF0000;"> http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"></span>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="WEB-INF/conf/hibernate.cfg.xml">
</property>
</bean>
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<tx:advice id="tx" transaction-manager="txManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" rollback-for="Exception" />
<tx:method name="save*" propagation="REQUIRED"
rollback-for="Exception" />
<tx:method name="remove*" propagation="REQUIRED"
rollback-for="Exception" />
<tx:method name="delete*" propagation="REQUIRED"
rollback-for="Exception" />
<tx:method name="update*" propagation="REQUIRED"
rollback-for="Exception" />
<tx:method name="register*" propagation="REQUIRED"
rollback-for="Exception" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="trAllMethod"
<span style="color:#009900;">expression="execution(* com.hsExt.service.*.*(..))" /></span>
<aop:advisor advice-ref="tx" pointcut-ref="trAllMethod" />
</aop:config>
</beans>
问题原因:Myeclipse不能识别<tx:advice/>标签,在定义申请AOP的时候,不能加载schema,在<beans >里加入如上述代码所示的代码片段,Myeclipse就能够识别<tx:advice/>,<aop:config/>;
代码片段中,几个通配符的含义:
第一个 * —— 通配任意返回值类型
第二个 * —— 通配com.hsExt.service包下的任意class
第三个 * —— 通配com.hsExt.service包下的任意class的任意方法
第四个 .. —— 通配方法可以有0个或多个参数
所以(* com.hsExt.service.*.*(..))匹配:包com.hsExt.service下的任意class的具有任意返回值类型、任意数目参数和任意名称的方法。