expression="execution(*service..*.*(..))"

本文介绍如何在Spring AOP中配置事务管理,通过使用通配符表达式来指定哪些类的方法需要进行事务控制。详细解析了通配符在表达式中的含义,并提供了具体的配置示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

(* 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>

老外喜欢吧逻辑运算符用or,and !写,国内一般用|| && !。

原文地址:http://hi.baidu.com/suofang/item/1bea72b7315c3497194697ea

 

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:task="http://www.springframework.org/schema/task" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd " > <context:property-placeholder location="classpath:application.properties"></context:property-placeholder> <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="packagesToScan" value="com.aiearth.drone.dao,com.aiearth.pojo" /> <property name="hibernateProperties"> <props> <!-- <prop key="hibernate.hbm2ddl.auto"> update </prop> --> <prop key="hibernate.dialect"> <!-- org.hibernate.spatial.dialect.postgis.PostgisDialect--> org.hibernate.spatial.dialect.postgis.PostgisPG10Dialect <!-- org.hibernate.dialect.PostgreSQLDialect--> </prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">false</prop> <prop key="hibernate.use_sql_comments">false</prop> <prop key="hibernate.temp.use_jdbc_metadata_defaults">false</prop> <prop key="hibernate.query.escape_like_parameter">false</prop> <prop key="hibernate.query.sql.escape-identifier">false</prop> <prop key="hibernate.logger.org.hibernate.mapping">DEBUG</prop> </props> </property> </bean> <bean id="dataSource" class="com.aiearth.drone.security.DataSource.UmspscDataSource"> <property name="driverClassName" value="org.postgresql.Driver"/> <property name="jdbcUrl" value="${drone.jdbc.url}?characterEncoding=utf8&serverTimezone=Asia/Shanghai&useSSL=false&stringtype=unspecified"/> <property name="username" value="${drone.jdbc.username}"/> <property name="password" value="${drone.jdbc.password}"/> <property name="connectionTimeout" value="30000"/> <property name="idleTimeout" value="180000"/> <property name="maximumPoolSize" value="30"/> <property name="minimumIdle" value="10"/> <property name="maxLifetime" value="1200000"/> <property name="connectionTestQuery" value="SELECT 1"/> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager" primary="true"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="get*" propagation="REQUIRED" /> <tx:method name="count*" propagation="REQUIRED" read-only="true" /> <tx:method name="find*" propagation="REQUIRED" read-only="true" /> <tx:method name="list*" propagation="REQUIRED" read-only="true" /> <tx:method name="*" /> </tx:attributes> </tx:advice> <aop:config expose-proxy="true"> <!-- 只对业务逻辑层实施事务 --> <aop:pointcut id="txPointcut" expression="execution(* com.aiearth..*.service..*Service.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut" /> </aop:config> </beans>这样配对吗,如果不对请给我完整的修改后配置
最新发布
07-31
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值