<aop:pointcut />

本文详细解释了AOP配置中的表达式execution(**..*Service.*(..)),深入探讨每个星号代表的意义,帮助开发者更好地理解和应用这一特性。

<aop:config> <aop:pointcut id="serviceMethod" expression="execution(* *..*Service.*(..))" />
</aop:config>


其中: expression="execution(* *..*Service.*(..))"
第一个* 表示任意返回值类型
第二个* 表示以任意名字开头的package. 如 com.xx.
第三个* 表示以任意名字开头的class的类名 如TestService
第四个* 表示 通配 *service下的任意class
最后二个.. 表示通配 方法可以有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:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd"> <!-- 引入外部配置文件 --> <context:property-placeholder location="classpath:jdbc.properties"/> <!-- 创建DataSource数据库连接池--> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="${jdbc.driver}"/> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> </bean> <!-- 创建JDBC Template对象 --> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> <property name="dataSource" ref="dataSource"/> </bean> <!-- 自定义对象 --> <bean id="user1Dao" class="com.my.company.dao.impl.User1DaoImpl"> <constructor-arg name="jdbcTemplate" ref="jdbcTemplate"/> </bean> <bean id="user1Service" class="com.my.company.service.impl.User1ServiceImpl"> <constructor-arg name="userDao" ref="user1Dao"/> </bean> <!-- Spring AOP 配置 --> <bean id="myAspect" class="com.my.company.aop.MyAspect"/> <aop:config> <aop:pointcut id="pt1" expression="execution(* com.my.company.service.impl.User1ServiceImpl.*(..))"/> <aop:aspect id="aspect1" ref="myAspect" order="1"> <aop:before method="before" pointcut-ref="pt1"/> <aop:after method="after" pointcut-ref="pt1"/> <aop:after-returning method="afterReturning" pointcut-ref="pt1"/> <aop:after-throwing method="afterThrowing" pointcut-ref="pt1"/> </aop:aspect> </aop:config> </beans>根据这个spring.xml文件举例生成spring和aop代码
09-05
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值