@Aspect 注解不起作用,原因可能出现在什么方面

SLLK 发布于 2017/03/14 18:41
阅读 993
收藏 0
public interface MethodInfoCheckService {
	/**
	 * 验证用户名和token
	 * 
	 * @param userId
	 * @param token
	 * @return
	 */
	public JSONObject initCheckRespose(String userId, String token);
}

 接口实现

@Service
public class MethodInfoCheckServiceImpl implements MethodInfoCheckService {

	@Resource
	private HibernateTemplate ht;

	@Override
	public JSONObject initCheckRespose(String userId, String token) {
		JSONObject jo = new JSONObject();
        //验证过程...
		return jo;
	}
}

切面类

@Component
@Aspect
public class MethodInfoCheckAfterAdvice{
	@Around(value="execution(* com.test.common.service..*.initCheckRespose(..))")
	public void aroundPoint(ProceedingJoinPoint pjp) {
		System.out.println("aroundPoint");
		System.out.println(pjp.getArgs().toString());
	}
}

使用postman调用接口可以获得返回值,但是切面并没有被调用。。。

pom.xml配置:

		<dependency>
			<groupId>org.aspectj</groupId>
			<artifactId>aspectjrt</artifactId>
			<version>1.8.1</version>
		</dependency>
		<dependency>
			<groupId>org.aspectj</groupId>
			<artifactId>aspectjweaver</artifactId>
			<version>1.8.1</version>
			<scope>runtime</scope>
		</dependency>

spring-mvc.xml配置

<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:mvc="http://www.springframework.org/schema/mvc"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation=
		"http://www.springframework.org/schema/mvc 
		http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
		http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
		http://www.springframework.org/schema/aop 
		http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context-3.2.xsd">

	<aop:aspectj-autoproxy proxy-target-class="true"/>

问题可能出现在哪里呢?

加载中
0
MnameHZJ
MnameHZJ
应该是表达式不对,把service..*.initCheck 改成 service.**.initCheck
0
秋痕
秋痕
<aop:aspectj-autoproxy proxy-target-class="true"/>

 这个配置  放在spring的配置xml里面  也就是applicationContext.xml 试一下

返回顶部
顶部