错误提示: 1:java.lang.IllegalStateException: Failed to load ApplicationContext

    2:Error creating bean with name 'userService' defined in class path resource [UserService.xml]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Cannot proxy target class because CGLIB2 is not available. Add CGLIB to the class path or specify proxy interfaces.

    3:Cannot proxy target class because CGLIB2 is not available. Add CGLIB to the class path or specify proxy interfaces.

根本原因:由于web在加载spring的配置文件(applicationContext.xml)时,发生了错误,而错误是3(cglib2不可用),所以根本原因是缺少cglib的包。

applicationContext.xml中的代理配置如下

  <!-- 指定使用cglib -->
    <aop:aspectj-autoproxy proxy-target-class="true" />
    
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="*" />
        </tx:attributes>
    </tx:advice>
    <!-- 通过AOP配置提供事务增强,让service包下所有bean的所有方法拥有事务 -->
    <aop:config proxy-target-class="true">
        <aop:pointcut id="serviceMethod" expression=" execution(* com.luxl.service..*(..))" />
        <aop:advisor pointcut-ref="serviceMethod" advice-ref="txAdvice" />
    </aop:config>

解决方法:在maven中添加cglib的包,如下:

  <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>2.2.2</version>
    </dependency>

spring中junit 提示Failed to load ApplicationContext的更多相关文章

  1. spring junit 做单元测试,报 Failed to load ApplicationContext 错误

    spring junit 做单元测试,报 Failed to load ApplicationContext 错误. 查找了好一会,最后发现.@ContextConfiguration(locatio ...

  2. 集成JUnit测试错误java.lang.IllegalStateException: Failed to load ApplicationContext

    1 详细错误信息 java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.t ...

  3. junit测试时,出现java.lang.IllegalStateException: Failed to load ApplicationContext

    课程设计要求进行junit测试,我是在已经做好的ssh项目上做的测试,测试类代码如下 package com.zhang.web.services; import static org.junit.A ...

  4. Junit 报错: Failed to load ApplicationContext

    今天在使用Junit测试时候,报了个错误: Failed to load ApplicationContext, aspect not found;挺奇怪的 我又没有调用你,之前还好好的,现在不能使用 ...

  5. junit单元测试报错Failed to load ApplicationContext,但是项目发布到tomcat浏览器访问没问题

    junit单元测试报错Failed to load ApplicationContext,但是项目发布到tomcat浏览器访问没问题,说明代码是没问题的,配置也没问题.开始时怀疑是我使用junit版本 ...

  6. SpringBoot报错:Failed to load ApplicationContext(Mapped Statements collection already contains value)

    错误提示: Caused by: java.lang.IllegalArgumentException: Mapped Statements collection already contains v ...

  7. SpringBoot报错:Failed to load ApplicationContext( Failed to bind properties under 'logging.level')

    引起条件: SpringBoot2.0下yml文件配置SLF4j日志输出日志级别 logging: level: debug 解决方法: 指定系统包路径 logging: root: debug 指定 ...

  8. Spring3.x 版本和 JDK1.8 不兼容导致 java.lang.IllegalStateException: Failed to load ApplicationContext

    由于安装了 JDK1.8 的版本,最近在进行整合 Struts2+Spring+Hibernate 框架的时候,不小心导入了之前下载的 Spring 3.2.0 版本的 jar 包. 结果在运行测试用 ...

  9. SpringBoot报错:Failed to load ApplicationContext(javax.websocket.server.ServerContainer not available)

    引起条件: WebSocket+单元测试,单元测试报错! 解决方法: SpringBootTest增加webEnvironment参数. https://docs.spring.io/spring-b ...

随机推荐

  1. 转:Apache-Tomcat各发布包说明

    下载地址:http://tomcat.apache.org/发布包说明: apache-tomcat-[version].zip---------------------------基本发布包.这些发 ...

  2. JQuery判断div(控件)是否为隐藏

    以下是JavaScript 中判断div是否为隐藏代码引用片段: if (div.style.display == "none") { div.style.display = &q ...

  3. checkbox设置单选的的两种方式

    一.如果 <input name="ck" type="checkbox">是页面加载就有的 $("#input[name=ck]&quo ...

  4. SCUT - 261 - 对称与反对称 - 构造 - 简单数论

    https://scut.online/p/261 由于M不是质数,要用扩展欧几里得求逆元,而不是费马小定理! 由于M不是质数,要用扩展欧几里得求逆元,而不是费马小定理! 由于M不是质数,要用扩展欧几 ...

  5. TP5之model

    使用model 查询数据,添加数据,修改数据,删除数据 聚合操作 获取器,修改器 自动添加时间戳(创建时间,修改时间) 软删除 1.使用model查询数据 $res = User::get(1); / ...

  6. 洛谷P4725 【模板】多项式对数函数(多项式运算)

    传送门 前置芝士:微积分(有所了解即可)(可以看看这篇,写得非常详细我看了两章就看不下去了) 以下都是一些简单的教程切莫当真,仅供理解,建议看更严谨的 导数:对于一个函数$f(x)$,它的导数$f'( ...

  7. 黑客攻防技术宝典web实战篇:攻击访问控制习题

    猫宁!!! 参考链接:http://www.ituring.com.cn/book/885 随书答案. 1. 一个应用程序可能通过使用 HTTP Referer 消息头实施访问控制,但它的正常行为并没 ...

  8. $BREEZE'S Diary$

    蒟蒻的日记没什么好看的. 2019-01-28 期末砸了. 洛谷开创小号. 开创博客园. 2019-01-29 坐标:义乌中学 咱今天又来义乌中学受虐了 感谢hjf给咱一次爆0的机会 题解 2019- ...

  9. Failed to convert property value of type 'java.util.LinkedHashMap' to required type 'java.util.Map' for property 'filters'

    在使用shiro的自定义filter出现的问题 <property name="filters"> <util:map> <entry key=&qu ...

  10. android 显示目录下图片

    知识点 1. 网格视图 2. 读取文件 MainAcitvity package com.test.gridview; import android.support.v7.app.AppCompatA ...