注:内有单词(sping)写错,请忽略,不影响程序运行

运行时报错:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mhl' defined in class path resource [myjava/wicherspingaop-aop.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#2': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.aop.aspectj.AspectJPointcutAdvisor]: 
Constructor threw exception; nested exception is java.lang.IllegalArgumentException: warning no match for this type name: res [Xlint:invalidAbsoluteTypeName]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:479)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at myjava.Main.main(Main.java:9)

代码如下:

Main.java

package myjava;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class Main {
public static void main(String[] args){
//获取IOC容器
ApplicationContext context = new ClassPathXmlApplicationContext("myjava/wicherspingaop-aop.xml");
Itest_1 mhl = context.getBean("mhl", Itest_1.class) ;
// mhl.sayHello();
mhl.saveToDB("zzzzz") ;
}
}

Itest_1.java

package myjava;

public interface Itest_1 {
void sayHello() ;
String saveToDB(String mData) ;
}

test_1.java

package myjava;

public class test_1 implements Itest_1 {
private String name ; public test_1(){
} public test_1(String name){
this.name = name ;
} public void setName(String name){
this.name = name ;
} public void sayHello(){
System.out.println("sayHello " + name);
} public String saveToDB(String mData){
System.out.println("SaveToDB: " + mData);
return "tt" ;
}
}

mylog.java

package myjava;

import org.aspectj.lang.ProceedingJoinPoint;

public class mylog {
// 1 - error; 2 - warn ; 3 - debug; 4 - info ;
private int loglvl = 3 ; public void info(String mlog){
if (loglvl == 4){
System.out.println("Info:" + mlog);
}
} public void debug(String mlog){
if (loglvl >= 3) {
System.out.println("debug:" + mlog);
}
} public void warn(String mlog){
if (loglvl >= 2) {
System.out.println("warn:" + mlog);
}
} public void error(String mlog){
if (loglvl >= 1) {
System.out.println("error:" + mlog);
}
} //前置通知
public void beforeAdvice(String messages){
System.out.println("前置通知, param:" + messages);
} //后置返回通知
public void afterReturn(String res){
System.out.println("后置返回通知,返回值:" + res);
//System.out.println("==============================");
} //后置异常通知
public void afterThrowing(Exception exception){
System.out.println("后置异常通知:" + exception);
} //后置最终通知
public void afterFinally(String messages){
System.out.println("后置最终通知:" + messages);
} //环绕通知
public String aroundAdvice(ProceedingJoinPoint joinPoint, String messages) throws Throwable{
try {
System.out.println("环绕通知,接入点:" + joinPoint + ",原param:" + messages);
System.out.println("放行目标方法并改变参数,将执行结果返回");
String res = (String) joinPoint.proceed(new Object[] {"param has been replaced "});
System.out.println("环绕通知改变了返回结果");
res = res.concat("& res has been changed");
System.out.println("返回结果为:"+res);
return res;
}catch (Exception e){
e.printStackTrace();
}
return null;
} }

wicherspingaop-aop.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:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd"
> <bean id = "mhl" class="myjava.test_1">
<property name="name" value="Wicher"></property>
</bean> <bean id = "log" class="myjava.mylog"></bean> <!--顶层的AOP配置元素,大多数的<aop:*>包含在<aop:config>元素内-->
<aop:config>
<!--定义外部切入点,该切入点可以被多个切面使用-->
<aop:pointcut id="pointcut_log" expression="execution(* myjava.test_1.* (..)) and args(messages)"/>
<!--定义切面-->
<aop:aspect ref="log">
<!--定义内部切入点,该切入点只能被当前切面使用-->
<!--<aop:pointcut id="pointcut_log_inner" expression="execution(* myjava.test_1.* (..)) and args(messages)"/>--> <!--前置通知-->
<aop:before method="beforeAdvice" arg-names="messages" pointcut-ref="pointcut_log"/>
<!--后置通知 不管该方法是否执行成功-->
<aop:after method="afterFinally" arg-names="messages" pointcut="execution(* myjava.test_1.* (..)) and args(messages)"/>
<!--后置返回通知 在方法成功执行后调用通知-->
<!--<aop:after-returning method="afterReturn" arg-names="res" returning="res" pointcut="execution(* myjava.test_1.* (..))"/>-->
<aop:after-returning method="afterReturn" arg-names="res" returning="res" pointcut="execution(* myjava.test_1.* (..)) and args(res)"/>
<!--后置异常通知 在方法抛出异常后调用通知-->
<aop:after-throwing method="afterThrowing" arg-names="exception" pointcut="execution(* myjava.test_1.* (..)) and args(exception)"/>
<!--环绕通知-->
<aop:around method="aroundAdvice" arg-names="joinPoint,messages" pointcut="execution(* myjava.test_1.* (..)) and args(messages)"/>
</aop:aspect>
</aop:config>
</beans>

工程路径

从网上down的demo能正常运行,自己先排错,把xml中环绕通知隐藏,运行正常,依次把前置通知(before),后置通知(after)取消隐藏,运行正常,再将after-returning取消隐藏时错,仔细与demo对比,发现在aop:after-returning的属性pointcut中是没有and args(res)的,去掉后运行正常, 因为对aop配置文件还不太熟,原因还不知道,后续确定原因后再记录。

全部lib文件如下(com.springsource.org.aspectj.weaver-1.6.4.RELEASE.jar是手工下载的,其他都是在建立spring时勾选的download自动下载):

后置通知

nested exception is java.lang.IllegalArgumentException: warning no match for this type name: res [Xlint:invalidAbsoluteTypeName]的更多相关文章

  1. Spring AOP 开发中遇到问题:Caused by: java.lang.IllegalArgumentException: warning no match for this type name: com.xxx.collector.service.impl.XxxServiceImpl [Xlint:invalidAbsoluteTypeName]

    在网上找了很多,都不是我想要的,后来发现是我在springaop注解的时候 写错了类名导致的这个问题 @Pointcut("execution(* com.xxx.collector.ser ...

  2. nested exception is java.lang.IllegalArgumentException: Pointcut is not well-formed

    在用AOP 的时候出现了如下的错误, 警告: Exception encountered during context initialization - cancelling refresh atte ...

  3. 异常:Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException

    这个异常是出现在注入配置文件中配置好的属性时报错的: Injection of autowired dependencies failed; nested exception is java.lang ...

  4. IDEA报错: Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.datasource.url' in value "${spring.datasource.url}"

    运行审核流模块: 在ActivitiServiceApplication模块日志报错: Error starting ApplicationContext. To display the auto-c ...

  5. org.hibernate.QueryException: JPA-style positional param was not an integral ordinal; nested exception is java.lang.IllegalArgumentException: org.hibernate.QueryException: JPA-style positional param w

    org.hibernate.QueryException: JPA-style positional param was not an integral ordinal; nested excepti ...

  6. Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: Pointcut is not well-formed: expecting 'name pattern' at character position 36

    例: <aop:config> <aop:pointcut expression="execution(* com.zsn.Service.Impl.*.*(..))&qu ...

  7. MyBatis与Spring MVC结合时,使用DAO注入出现:Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required

    错误源自使用了这个例子:http://www.yihaomen.com/article/java/336.htm,如果运行时会出现如下错误: Invocation of init method fai ...

  8. HTTP Status 500 - Request processing failed; nested exception is java.lang.IllegalArgumentException: Control character in cookie value or attribute.

    HTTP Status 500 - Request processing failed; nested exception is java.lang.IllegalArgumentException: ...

  9. org.springframework.dao.InvalidDataAccessApiUsageException: The given id must not be null!; nested exception is java.lang.IllegalArgumentException: The given id must not be null

    通过这个简单的案例,手把手教给你分析异常信息(适合初学者看) org.springframework.dao.InvalidDataAccessApiUsageException: The given ...

随机推荐

  1. R 创建一个空的数据框

    k = 16 #数据框的行数 z = data.frame( a = numeric(k), b = numeric(k), c = numeric(k), d = numeric(k) )

  2. 偶然在博客中见对百度一个面试题的探讨,写些自己的看法以及指出探讨中不对的观点:百度面试题:求绝对值最小的数 有一个已经排序的数组(升序),数组中可能有正数、负数或0,求数组中元素的绝对值最小的数,要求,不能用顺序比较的方法(复杂度需要小于O(n)),可以使用任何语言实现 例如,数组{-20,-13,-4, 6, 77,200} ,绝对值最小的是-4。

    今天申请了博客园账号,在下班后阅览博客时发现了一个关于百度面试题探讨的博客(其实是个很基础的问题),此博客url为:http://www.blogjava.net/nokiaguy/archive/2 ...

  3. 吴裕雄--天生自然java开发常用类库学习笔记:大数操作

    import java.math.* ; class MyMath{ public static double add(double d1,double d2){ // 进行加法计算 BigDecim ...

  4. Window Server 2019 配置篇(5)- 在域中建立WSUS以实现自动更新

    上次讲到我们的服务器群中增加了一台用于自动部署的服务器,这次我们要添加一台搭载WSUS服务的服务器,以实现对window更新的管理 那么WSUS是什么服务呢? WSUS是window server u ...

  5. chrome常用参数

    chrome禁止本地浏览时加载本地其他文件,可以采用添加启动参数的方式来支持 添加参数为 --allow-file-access-from-files 或者 --disable-web-securit ...

  6. POJ3295 Tautology重言式

    Tautology 思路很简单,对于p.q.r.s.t暴力枚举是0还是1,判断即可.判断时像写表达式求值那样用栈.为了方便可以从后往前,因为最后一个肯定不是运算.那几个奇奇怪怪的函数可以找规律然后转为 ...

  7. knockoutjs 经验总结

    http://knockoutjs.com/documentation/introduction.html knockout的模式 MVVM 四大重要概念 声明式绑定UI界面自动刷新依赖跟踪模版 一些 ...

  8. node - 路由的使用

    一,服务器文件 app.js  .( 要使用路由的文件)   const express = require('express') const app = express() const swig = ...

  9. bzoj 2451 Uyuw's Concert

    裸的半平面交.感觉这些东西,纯属在考代码能力啊.. #include<cstdio> #include<algorithm> #include<cmath> #de ...

  10. 备份CSDN

    说明:https://blog.csdn.net/Feynman1999/article/details/87908082 源码:https://github.com/Feynman1999/CSDN ...