Spring框架aop开启前置通知遇到的bug

恒温 发布于 2016/09/11 19:10
阅读 266
收藏 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:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	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-3.0.xsd
       http://www.springframework.org/schema/context 
       http://www.springframework.org/schema/context/spring-context-3.0.xsd
       http://www.springframework.org/schema/tx 
       http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"
	xmlns:jpa="http://www.springframework.org/schema/data/jpa">
		<context:component-scan base-package="cn.cj"/>
		<aop:aspectj-autoproxy />
</beans>



package cn.cj.service.impl;

import org.springframework.stereotype.Service;

import cn.cj.service.PersonService;

@Service
public class PersonServiceBean implements PersonService {
	public PersonServiceBean personServiceBean;
	public void save(String name) {
		System.out.println("save()方法");
	}

	public void update(String name, Integer id) {
		System.out.println("update方法");
	}

	public String getPersonName(Integer id) {
		System.out.println("getPersonName方法");
		return "xxx";
	}

}



package cn.cj.service; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; import org.springframework.stereotype.Component; @Aspect @Component public class MyInterceptor { @Pointcut("execution(* cn.cj.service.impl..*.*(..))") public void anyNerhod(){}// 申明一个切入点 @Before("anyNerhod()") public void doAccessCheck(String userName){ System.out.println("前置通知"); } }


代码如上。。启动aop之后无法将代码托管给Spring框架管理。。

加载中
返回顶部
顶部