Spring 里面XML配置AOP时 报错

cqwish16 2012-11-28 10:41:08
直接发代码 各位帮忙看看

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>

...全文
165 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wanbing1986 2014-04-07
  • 打赏
  • 举报
回复
什么问题也不说
cqwish16 2012-11-28
  • 打赏
  • 举报
回复
Ok 搞定了 谢谢啊 呵呵 不是那个问题
cqwish16 2012-11-28
  • 打赏
  • 举报
回复
还是报错 还是有点问题 是环境的问题么? 不应该吧。。 其他的都可以跑
安特矮油 2012-11-28
  • 打赏
  • 举报
回复
<aop:pointcut id="mycut" expression="execution(* com.jinoux.personservice.impl.*(..))" /> 改成 <aop:pointcut id="mycut" expression="execution(* com.jinoux.personservice.*(..))" />试试
cqwish16 2012-11-28
  • 打赏
  • 举报
回复
我一直在看 XMl配置的文件 我估计是这儿出错了 但是看了老半天了 一直没看出来 所以才来求助各位了
cqwish16 2012-11-28
  • 打赏
  • 举报
回复
程序运行的时候报错:


控制台:十一月 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

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧