请大家帮忙看看为什么spring mvc aop的Aspect配置不起作用
项目采用controller-service-dao结构1、先看看servlet配置文件<bean id="logAspect" class="com.guardlbt.lottery.log.LogAspect">
<property name="logService" ref="logService"></property>
</bean>
<!-- 使用AspectJ方式 -->
<aop:aspectj-autoproxy proxy-target-class="true"/>2、LogAspect.java
package com.guardlbt.lottery.log;import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import com.guardlbt.lottery.service.admin.LogService;
@Aspect //该注解标示该类为切面类
public class LogAspect {
private LogService logService;
public LogService getLogService() {
return logService;
} public void setLogService(LogService logService) {
this.logService = logService;
}
@AfterReturning("@annotation (com.guardlbt.lottery.log.LotteryLog)")
public void afterReturning(){
System.out.println("Aop invoked!!!");
}
}3、LotteryLog.java
package com.guardlbt.lottery.log;import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; @Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface LotteryLog {
String desc() default "desc";
}
4、在service层的应用,
@LotteryLog(desc="insert user")
public boolean insert(User user) throws Exception {
return userDao.insert(user);
}
项目采用controller-service-dao结构1、先看看servlet配置文件<bean id="logAspect" class="com.guardlbt.lottery.log.LogAspect">
<property name="logService" ref="logService"></property>
</bean>
<!-- 使用AspectJ方式 -->
<aop:aspectj-autoproxy proxy-target-class="true"/>2、LogAspect.java
package com.guardlbt.lottery.log;import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import com.guardlbt.lottery.service.admin.LogService;
@Aspect //该注解标示该类为切面类
public class LogAspect {
private LogService logService;
public LogService getLogService() {
return logService;
} public void setLogService(LogService logService) {
this.logService = logService;
}
@AfterReturning("@annotation (com.guardlbt.lottery.log.LotteryLog)")
public void afterReturning(){
System.out.println("Aop invoked!!!");
}
}3、LotteryLog.java
package com.guardlbt.lottery.log;import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; @Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface LotteryLog {
String desc() default "desc";
}
4、在service层的应用,
@LotteryLog(desc="insert user")
public boolean insert(User user) throws Exception {
return userDao.insert(user);
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货