Spring切入点表达式 expression="execution(*service..*.*(..))"

(* com.evan.crm.service.*.*(..))中几个通配符的含义: 


|第一个 * —— 通配 随便率性返回值类型| 
|第二个 * —— 通配包com.evan.crm.service下的随便率性class| 
|第三个 * —— 通配包com.evan.crm.service下的随便率性class的随便率性办法| 
|第四个 .. —— 通配 办法可以有0个或多个参数| 


 

 

<!-- 配置那些类的方法进行事务管理 --> 
<aop:config> 
<aop:pointcut id="allServiceMethod" expression="execution (* com.cms.sys.service.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="allServiceMethod" /> 
</aop:config> 

还有一个 
execution (* com.cms.art.service.*.*(..))" 

要怎么写?

可以这样写:将execution分开写。 
<aop:config> 
<aop:pointcut id="allServiceMethod" expression="(execution (* com.cms.sys.service.*.*(..)))or (execution (* com.cms.art.service.*.*(..)))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="allServiceMethod" /> 
</aop:config> 

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
代码报错<?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:comtext="http://www.springframework.org/schema/context" 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/util http://www.springframework.org/schema/util/spring-util.xsd"> <!-- 1 准备目标类 --> <bean id="personDao" class="com.sc.spring.dao.impl.PersonDaoImpl"></bean> <!-- 2 准备增强类 --> <bean id="myAdvice" class="com.sc.spring.utils.MyAdvice"></bean> <!-- 3 织入 将增强类的增强方法应用到目标类的目标方法前后 --> <aop:config> <!-- pointcut标签声明切入点表达式 切入点表达式就是一种规则 spring aop根据规则找到满足规则的目标方法 然后对目标方法前后进行指定增强 --> <aop:pointcut id="pc" expression="execution(public boolean com.sc.spring.dao.impl.PersonDaoImpl.getPersonByUsernameAndPwd(java.lang.String,java.lang.String))"></aop:pointcut> <aop:aspect ref="myAdvice"> <!-- aop:before标签代表配置前置通知 method属性是配置增强类中哪个方法作为前置通知执行 --> <aop:before method="before" pointcut-ref="pc"></aop:before> </aop:aspect> </aop:config> </beans>报错问题是org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 22 in XML document from class path resource [aop.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 22; columnNumber: 17; cvc-complex-type.2.4.c: 通配符的匹配很全面, 但无法找到元素 'aop:config' 的声明。
最新发布
06-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值