转:

(报错解决)Exception encountered during context initialization

关键词

JavaEE JavaWeb eclipse XML AspectJ

描述

1.报错记录。摸索中。轻喷。
2.《Java EE框架整合开发入门到实战:Spring+Spring MVC+MyBatis(微课版)》4.4节“基于XML配置开发AspectJ”

报错

警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testDao' defined in class path resource [aspectj/xml/applicationContext.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#1': Cannot create inner bean '(inner bean)#57175e74' of type [org.springframework.aop.aspectj.AspectJAfterReturningAdvice] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#57175e74': Cannot create inner bean '(inner bean)#7bb58ca3' of type [org.springframework.aop.config.MethodLocatingFactoryBean] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#7bb58ca3': Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: Unable to locate method [afterReturning] on bean [myAspect]

检查

拖到最右边查看报错

Unable to locate method [afterReturning] on bean [myAspect]

就是说bean实例myAspect中的方法afterReturning有问题。

检查MyAspect.java中的方法afterReturning。与applicationContext.xml对应位置进行比较。
 
 
发现是MyAspect.java中的方法afterReturning拼写有问题(多写了个n)。与applicationContext.xml对应不上。

解决

将MyAspect.java中的方法afterReturnning改为afterReturning。与applicationContext.xml中的afterReturning对应上。

总结

1.查看eclipse报错部分的最上面的最右边
2.检查xml文件以及报错提示的bean对应java文件。

(补充)项目

结构

package aspectj.xml;

applicationContext.xml


MyAspect.java
package aspectj.xml;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint; //切面类,在此类中编写各种类型的通知
public class MyAspect {
//前置通知,使用JoinPoint接口作为参数获得目标对象信息
public void before(JoinPoint jp){
System.out.println("前置通知:模拟权限控制");
System.out.println(",目标类对象:"+jp.getTarget()+",被增强处理的方法:"+jp.getSignature().getName());
} //后置返回通知
public void afterReturnning(JoinPoint jp){
System.out.println("后置返回通知:"+"模拟删除临时文件");
System.out.println(",被增强处理的方法"+jp.getSignature().getName());
} /**
* 环绕通知
* ProceedingJoinPoint是JoinPoint的子接口,代表可以执行的目标方法
* 返回值的类型必须是一个Object
* 必须一个参数是ProceedingJoinPoint类型
* 必须throws Throwable
* @param pjp
* @return
* @throws Throwable
*/
public Object around(ProceedingJoinPoint pjp) throws Throwable{
//开始
System.out.println("环绕开始:执行目标方法前,模拟开始事务");
//执行当前目标方法
Object obj = pjp.proceed();
//结束
System.out.println("环绕结束:执行目标方法后,模拟关闭事务");
return obj;
} //异常通知
public void except(Throwable e){
System.out.println("异常通知:"+"程序执行异常"+e.getMessage());
} //后置(最终)通知
public void after(){
System.out.println("最终通知:模拟释放资源");
}
}
XMLAspectJTest.java
package aspectj.xml;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import dynamic.jdk.TestDao; public class XMLAspectJTest {
//在主方法中使用Spring容器获取代理对象,并执行目标方法
public static void main(String[] args) {
ApplicationContext appCon = new ClassPathXmlApplicationContext("/aspectj/xml/applicationContext.xml");
//从容器中获取增强后的目标对象
TestDao testDaoAdvice = (TestDao)appCon.getBean("testDao");
//执行方法
testDaoAdvice.save();
/*
前置通知:模拟权限控制
,目标类对象:dynamic.jdk.TestDaoImpl@45b9a632,被增强处理的方法:save
环绕开始:执行目标方法前,模拟开始事务
保存
最终通知:模拟释放资源
环绕结束:执行目标方法后,模拟关闭事务
后置返回通知:模拟删除临时文件
,被增强处理的方法save
*/
} }

package dynamic.jdk;

TestDao.java
package dynamic.jdk;

public interface TestDao {
public void save();
public void modify();
public void delete();
}
TestDaoImpl.java
package dynamic.jdk;

//该实现类作为目标类,在代理类中对实现类的方法进行增强处理
public class TestDaoImpl implements TestDao { @Override
public void save() {
System.out.println("保存");
} @Override
public void modify() {
System.out.println("修改");
} @Override
public void delete() {
System.out.println("删除");
}
}

运行结果(运行XMLAspectJTest.java)

转:

(报错解决)Exception encountered during context initialization

(报错解决)Exception encountered during context initialization的更多相关文章

  1. 【flyway】Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' def

    报错如下: "2018-03-20 12:58:09.585 WARN 18026 — [ restartedMain] ConfigServletWebServerApplicationC ...

  2. Spring AOP:Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException

    1 报错 Exception encountered during context initialization - cancelling refresh attempt: org.springfra ...

  3. org.springframework.web.context.support.XmlWebApplicationContext.refresh Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreatio

    错误异常: 11-Apr-2019 18:07:14.006 警告 [RMI TCP Connection(5)-127.0.0.1] org.springframework.web.context. ...

  4. 开发Spring过程中几个常见异常(二):Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'a' define

    本异常是小编在运行自己另外一篇博文中的例子时遇到的.(附博文:http://www.cnblogs.com/dudududu/p/8482487.html) 完整异常信息: 警告: Exception ...

  5. nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.报错解决

    近期在学springboot,学的时候遇到这个错,网上查了好多,改了不行,后来发现自己的配置类没有加@SpringBootApplication注解 Exception encountered dur ...

  6. org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 3报错解决

    报错的原因翻译出来: 预期的一个结果(或null)返回selectOne(),但发现:3 意思就是你想得到一个结果值,但是返回了三个结果值. 一般可能测试的时候我们存了几条一样的数据,在登录时,会把同 ...

  7. Spring Cloud和eureka启动报错 解决版本依赖关系

    导读 An attempt was made to call a method that does not exist. The attempt was made from the following ...

  8. redis运用连接池报错解决

    redis使用连接池报错解决redis使用十几小时就一直报异常 redis.clients.jedis.exceptions.JedisConnectionException: Could not g ...

  9. eclipse运行项目,tomcat报错:Exception in thread :http-bio-8080-exec-4

    eclipse运行项目,tomcat报错:Exception in thread :http-bio-8080-exec-4 转自 https://www.cnblogs.com/yby-blogs/ ...

随机推荐

  1. hdu2141 Can you find it? (二分)

    Problem Description Give you three sequences of numbers A, B, C, then we give you a number X. Now yo ...

  2. CodeForces - 916C 思维

    题意:给你n,m,表示n个顶点和m条边,让你构造一个图. 要求 1.1->n最短路为素数 2.最小生成树边权和为prime 3.没有重边 4.边大小[1,1e9]. (题目给定m>n-1) ...

  3. win7 & centos7 双系统安装方法

    1.准备 1)Centos7镜像 官方:https://www.centos.org/ 阿里镜像:http://mirrors.aliyun.com/centos/ 2)安装windows7系统的电脑 ...

  4. ef学习记录

    EF Core (EntityFramework Core)是实体关系映射(O/RM)数据库访问框架.这个模式的好处就是让开发人员可以用对象模型来操作数据库,这是一种对开发人员较为友好的方式. O/R ...

  5. CDN 概述

    占位 CDN(Content Delivery Network)内容发布网络 推荐Blog: CDN 学习笔记

  6. FZU 2082 过路费(树链剖分 边权)题解

    题意:给出每条边权值,可以更新每条边权值,询问两个点路径的最小权值 思路:重链剖分边权化点权,让每个儿子节点继承边权. 插点权的时候比较边的两个节点的深度,插进儿子节点中. 代码: #include& ...

  7. 洛谷p1637 三元上升子序列(树状数组

    题目描述 Erwin最近对一种叫"thair"的东西巨感兴趣... 在含有n个整数的序列a1,a2......an中, 三个数被称作"thair"当且仅当i&l ...

  8. 深入剖析JavaScript中的数据类型判断(typeof instanceof prototype.constructor)

    关于JavaScript中的类型判断,我想大部分JavaScripter 都很清楚 typeof 和  instanceof,却很少有人知道 constructor,以及constructor与前面二 ...

  9. console.clear

    console.clear Chrome console.clear && console.clear() refs xgqfrms 2012-2020 www.cnblogs.com ...

  10. how to config custom process.env in node.js

    how to config custom process.env in node.js process.env APP_ENV NODE_ENV https://nodejs.org/api/proc ...