Spring 里面XML配置AOP时 报错
直接发代码 各位帮忙看看
package com.jinoux.personservice;
/**
* 接口
* @author Cary
*
*/
public interface PersonServiceDao {
public void save();
}
package com.jinoux.personservice.impl;
import com.jinoux.personservice.PersonServiceDao;
/**
* 业务类
* @author Cary
*
*/
public class PersonServiceBean implements PersonServiceDao{
public void save() {
System.out.println("save()方法");
}
}
package com.jinoux.personservice;
import org.aspectj.lang.ProceedingJoinPoint;
/**
* 切面
* @author Cary
*
*/
public class MyInterceptor {
public void doAccessCheck(){
System.out.println("前置通知");
}
public void doAfterReturning(){
System.out.println("后置通知");
}
public void doAfter(){
System.out.println("最终通知");
}
public void doAfterThrowing(){
System.out.println("例外通知");
}
public Object doBasicProfiling(ProceedingJoinPoint pjp)throws Throwable{
System.out.println("进入方法");
Object result = pjp.proceed();
System.out.println("退出方法");
return result;
}
}
package junit.test;
import static org.junit.Assert.*;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.jinoux.personservice.PersonServiceDao;
/**
* 测试
* @author Cary
*
*/
public class SpringTest {
@Test
public void test() {
ApplicationContext cxt = new ClassPathXmlApplicationContext("beans.xml");
PersonServiceDao personserivcedao = (PersonServiceDao) cxt.getBean("personservice");
personserivcedao.save();
}
}
XML
<?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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<bean id="personservice" class="com.jinoux.personservice.impl.PersonServiceBean"></bean>
<!-- 把切面交给Bean -->
<bean id="myInterceptor" class="com.jinoux.personservice.MyInterceptor" />
<aop:config>
<!-- 切面 -->
<aop:aspect id="asp" ref="myInterceptor">
<!-- 切点 -->
<aop:pointcut id="mycut" expression="execution(* com.jinoux.personservice.impl.*(..))" />
<!-- 切面里面的方法 -->
<aop:before pointcut-ref="mycut" method="doAccessCheck"/>
</aop:aspect>
</aop:config>
</beans>
[最优解释]
<aop:pointcut id="mycut" expression="execution(* com.jinoux.personservice.impl.*(..))" />
改成
<aop:pointcut id="mycut" expression="execution(* com.jinoux.personservice.*(..))" />试试
[其他解释]
程序运行的时候报错:
控制台:十一月 28, 2012 10:27:51 上午 org.springframework.context.support.AbstractApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@5e7663: display name [org.springframework.context.support.ClassPathXmlApplicationContext@5e7663]; startup date [Wed Nov 28 10:27:51 CST 2012]; root of context hierarchy
十一月 28, 2012 10:27:51 上午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [beans.xml]
十一月 28, 2012 10:27:51 上午 org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
信息: Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@5e7663]: org.springframework.beans.factory.support.DefaultListableBeanFactory@594d1d
十一月 28, 2012 10:27:51 上午 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
信息: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@594d1d: defining beans [personservice,myInterceptor,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.aop.aspectj.AspectJPointcutAdvisor#0,mycut]; root of factory hierarchy
十一月 28, 2012 10:27:51 上午 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
信息: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@594d1d: defining beans [personservice,myInterceptor,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.aop.aspectj.AspectJPointcutAdvisor#0,mycut]; root of factory hierarchy
[其他解释]
我一直在看 XMl配置的文件 我估计是这儿出错了 但是看了老半天了 一直没看出来 所以才来求助各位了
[其他解释]
还是报错 还是有点问题 是环境的问题么? 不应该吧。。 其他的都可以跑
[其他解释]
Ok 搞定了 谢谢啊 呵呵 不是那个问题