`
思念-悲伤
  • 浏览: 24652 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

编写aop:around时出现的异常org.springframework.aop.AopInvocationException:

阅读更多

 Exception in thread "main"org.springframework.aop.AopInvocationException: Null return value from advice does not match primitive return type for: public boolean org.spring.aop.User.login(java.lang.String,java.lang.String)
at org.springframework.aop.framework.CglibAopProxy.processReturnType(CglibAopProxy.java:351)
at org.springframework.aop.framework.CglibAopProxy.access$000(CglibAopProxy.java:83)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:646)
at org.spring.aop.User$$EnhancerBySpringCGLIB$$db4a87bb.login(<generated>)

at lee.UserApp.main(UserApp.java:14)

在编写aop代码时,出现了上述的异常。我使用的是around类型的通知方法:我的aop代码如下:

 

package org.spring.aop;

import org.aspectj.lang.ProceedingJoinPoint;

public class LoginService {
	public void enter(String account,String password){
		System.out.println("some one ....");
		System.out.println("账号:"+account);
		System.out.println("密码:"+password);
	}
	
public void leave(ProceedingJoinPoint joinpoint,String account,String password) throws Throwable{
		System.out.println("-------------------调用通知之前,around-------------");
		Object obj = joinpoint.proceed();
		System.out.println("------------------调用通知之后,around--------------");
		System.out.println("Is s ucceeded?" + obj);
		obj=false;
//		return obj;
	}
}
	public boolean login(String account,String password){
		System.out.println("--------login-------------");
		return this.account.equals(account)&&
				this.password.equals(password);
	}

出错的原因是因为:org.springframework.aop.AopInvocationException: Null return value from advice does not match primitive return type for: public boolean org.spring.aop.User.login(java.lang.String,java.lang.String)

即:在调用around的时候,原方法的返回值(也就是你要织入的方法)与通知的返回值不一致。

从代码中看出:我是void 没有返回值,而我的login的方法是由返回值的!

所以修改方法是:aop代码中leave方法的返回值类型改为与织入方法返回值一样的类型。

我上面的代码修改方法是:把void 改为 Object。

分享到:
评论

相关推荐

    springAOP demo 带错误解决文档

    nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator]: ...

    Spring AOP配置源码

    import org.springframework.stereotype.Component; @Component("userDAO") public class UserDao { public void say() { System.out.println("say method is called"); } public void smile() { System.out...

    spring aop 实现源代码--xml and annotation(带lib包)

    顾名思义,Before Advice会在目标对象的方法执行之前被调用,您可以通过实现org.springframework.aop.MethodBeforeAdvice接口来实现Before Advice的逻辑,接口定义如下: java 代码 1. package org.spring...

    Spring  AOP实现方法大全

    顾名思义,Before Advice会在目标对象的方法执行之前被调用,您可以通过实现org.springframework.aop.MethodBeforeAdvice接口来实现Before Advice的逻辑,接口定义如下: java 代码 1. package org.springframework....

    利用AOP来变更工作线程的名字,来快速过滤出一次请求的所有日志.docx

    至于为什么要改threadName,为什么要用AOP,就不再铺垫赘述了。Talk is cheap, show me thecode。下面代码可以直接使用,拿走不谢。...import org.springframework.stereotype.Component; import java.util.Random;

    spring-framework-reference-4.1.2

    3. New Features and Enhancements in Spring Framework 4.0 ............................................ 17 3.1. Improved Getting Started Experience .........................................................

    spring-framework-reference4.1.4

    3. New Features and Enhancements in Spring Framework 4.0 ............................................ 17 3.1. Improved Getting Started Experience .........................................................

    SpringFramework中的面向方面编程(AOP),第二部分

    利用Spring框架所提供的面向方面编程(Aspect-OrientedProgramming,AOP)功能,您看到了如何使用before-、after-和基于异常的通知,以及如何使用基于正则表达式的简单切入点。跟踪和记录方面提供了非常不错的上手例子...

    开源框架 Spring Gossip

    org.springframework.mail.javamail.JavaMailSenderImpl。 简单邮件 HTML 邮件 内嵌图片或附档 排程 Spring则对 java.util.Timer提供了抽象封装,让您可以善用Spring的容器管理功能,而Spring对...

    springboot学习思维笔记.xmind

    Spring TestContext Framework集成测试 SpringMVC基础 Spring MVC概述 SpringMVC项目快速搭建 构建Maven项目 日志配置 演示页面 Spring MVC配置 Web配置 简单控制器 运行 Spring MVC...

Global site tag (gtag.js) - Google Analytics