我用SSM框架,写这个日志,总是切不进去,也不知道是什么原因,找不到错误,
个人猜测是不是配置文件扫描类有问题。项目能正常运行,增删改查都没问题,就这个AOP搞不定,就知道帮忙谢谢。
@Aspect
@Component
public class OperateLogHandler {
@Resource
private OperateLogService operateLogService;// 操作日志Service
/**
* 添加业务逻辑方法切入点
*/
@Pointcut("execution(* com.szkingdom.cdpf.admin.service.impl.*.save*(..))")
public void saveServiceCall() {
}
/**
* 修改业务逻辑方法切入点
*/
@Pointcut("execution(* com.szkingdom.cdpf.admin.service..*.update*(..))")
public void updateServiceCall() {
}
/**
* 删除业务逻辑方法切入点
*/
@Pointcut("execution(* com.szkingdom.cdpf.admin.service..*.delete*(..))")
public void deleteServiceCall() {
}
/**
* 操作员添加操作日志(后置通知)
*/
@Before(value="saveServiceCall()")
public void saveServiceCallCalls(JoinPoint joinPoint) throws Throwable{
System.out.println("出现吧,出现把,出现把");
web.xml是这样的
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/applicationContext*.xml</param-value>
<!-- 配置监听器 -->
org.springframework.web.context.ContextLoaderListener
com.szkingdom.cdpf.web.listener.ServerStartupListener
<!-- 字符编码过滤器 -->
encoding
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
forceEncoding
true
encoding
*.do
<!-- 配置框架前端控制器 -->
springmvc
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:springmvc/springmvc-servlet.xml
1
springmvc
*.do
springmvc-servlet.xml文件是这样的
<!-- 启用注解功能 -->
<context:annotation-config />
<context:component-scan base-package="com.szkingdom.cdpf.*" />
<mvc:annotation-driven />
略。。
applicationContext.xml文件是这样的
<!-- 启用AOP功能 -->
<aop:aspectj-autoproxy/>
略
。。。。
<!-- TransactionManager -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 事务通知Advice。Aspect是横切面,抽象的,Advice是具体存在的Aspect
AOP功能增强器
-->
<tx:advice id="transactionAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="insert*" propagation="REQUIRED" isolation="DEFAULT" rollback-for="java.lang.Exception"/>
<tx:method name="delete*" propagation="REQUIRED" isolation="DEFAULT" rollback-for="java.lang.Exception"/>
<tx:method name="update*" propagation="REQUIRED" isolation="DEFAULT" rollback-for="java.lang.Exception"/>
<tx:method name="select*" read-only="true"/>
<tx:method name="*" propagation="REQUIRED" isolation="DEFAULT" rollback-for="java.lang.Exception"/>
</tx:attributes>
</tx:advice>
<!-- 切入 -->
<aop:config>
<aop:advisor advice-ref="transactionAdvice" pointcut="execution(* com.szkingdom.cdpf.admin.service..*.*(..))"/>
</aop:config>
我这事务感觉不太对,先不管,