博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java.lang.IllegalStateException: Failed to load ApplicationContext
阅读量:5832 次
发布时间:2019-06-18

本文共 6102 字,大约阅读时间需要 20 分钟。

摘要

在配置spring aop的时候总是出现下面的错误,找了很多种办法,这篇文字给了自己点灵感,通过这种方式解决了。

参考:

解决办法

Note that the Java 8 bytecode level (-target 1.8, as required by -source 1.8) is only fully supported as of Spring Framework 4.0. In particular, Spring 3.2 based applications need to be compiled with a maximum of Java 7 as the target, even if they happen to be deployed onto a Java 8 runtime. Please upgrade to Spring 4 for Java 8 based applications.

大概的意思就是java1.8版本只支持spring4.0以上。所以解决方法有2中①把sping版本换成4.0以上②把jdk调低点。

error信息

java.lang.IllegalStateException: Failed to load ApplicationContext    at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:157)    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener .injectDependencies(DependencyInjectionTestExecutionListener.java:109)    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener .prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:313)    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:284)    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)Caused by: java.lang.IllegalArgumentException    at org.springframework.asm.ClassReader.
(Unknown Source) at org.springframework.asm.ClassReader.
(Unknown Source) at org.springframework.asm.ClassReader.
(Unknown Source) at org.springframework.core.type.classreading.SimpleMetadataReader.
(SimpleMetadataReader.java:52) at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80) at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:101) at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:76) at org.springframework.context.annotation.ConfigurationClassUtils.checkConfigurationClassCandidate(ConfigurationClassUtils.java:70) at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor .java:253) at org.springframework.context.annotation.ConfigurationClassPostProcessor .postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:223) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:630) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461) at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:106) at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:57) at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader .delegateLoading(AbstractDelegatingSmartContextLoader.java:100) at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader .loadContext(AbstractDelegatingSmartContextLoader.java:248) at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:124) at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:148) ... 23 more

spring 整合junit

package com.sp.demo;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.test.context.ContextConfiguration;import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;import javax.annotation.Resource;@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration("classpath:applicationContext.xml")public class OrderDaoTest {    @Resource(name = "orderDao")    private OrderDao orderDao;    @Test    public void run() {//        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");//        orderDao  = (OrderDao) context.getBean("orderDao");        this.orderDao.save();        this.orderDao.find();    }}

applicationContext.xml

我使用的是IDE是Idea,可以通过下面的方式进行修改

File->Project Structure->Project 

修改为

到此解决

转载于:https://www.cnblogs.com/wolf-sun/p/9138839.html

你可能感兴趣的文章
智慧城市首要在政府利用大数据的智慧
查看>>
2015年物联网行业:巨头展开专利大战
查看>>
以自动化测试撬动遗留系统
查看>>
网络安全初创公司存活之道
查看>>
《图解CSS3:核心技术与案例实战》——1.2节浏览器对CSS3的支持状况
查看>>
《Android应用开发》——2.4节应用类
查看>>
继 One Step 后,锤子科技 Big Bang 正式开源
查看>>
《淘宝店铺经营管理一册通》一一1.4 商品发布
查看>>
《数据科学:R语言实现》——2.5 使用Excel文件
查看>>
《淘宝店铺设计装修一册通》一2.5 抠图工具的简单运用
查看>>
《音乐达人秀:Adobe Audition实战200例》——实例4 收音机音乐节目转录到电脑里...
查看>>
《JavaScript应用程序设计》一一3.1 过时的类继承
查看>>
千万PV是什么意思?
查看>>
Amazon 推出 API 网关使用计划
查看>>
互联网流量超出路由器上限 或致全球断网
查看>>
《基于ArcGIS的Python编程秘笈(第2版)》——2.5 限制图层列表
查看>>
GNOME 地图 3.20 加入更多新特性 可用性得到加强
查看>>
《代码整洁之道:程序员的职业素养》导读
查看>>
《计算复杂性:现代方法》——习题
查看>>
Mozilla 释出更新修复中间人攻击漏洞
查看>>