摘要
在配置spring aop的时候总是出现下面的错误,找了很多种办法,这篇文字给了自己点灵感,通过这种方式解决了。
解决办法
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信息
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:</span>157<span style="color: #000000;">)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener<br>.injectDependencies(DependencyInjectionTestExecutionListener.java:</span>109<span style="color: #000000;">)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener<br>.prepareTestInstance(DependencyInjectionTestExecutionListener.java:</span>75<span style="color: #000000;">)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:</span>313<span style="color: #000000;">)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:</span>211<span style="color: #000000;">)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$</span>1.runReflectiveCall(SpringJUnit4ClassRunner.java:288<span style="color: #000000;">)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:</span>12<span style="color: #000000;">)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:</span>284<span style="color: #000000;">)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:</span>231<span style="color: #000000;">)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:</span>88<span style="color: #000000;">)
at org.junit.runners.ParentRunner$</span>3.run(ParentRunner.java:290<span style="color: #000000;">)
at org.junit.runners.ParentRunner$</span>1.schedule(ParentRunner.java:71<span style="color: #000000;">)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:</span>288<span style="color: #000000;">)
at org.junit.runners.ParentRunner.access$</span>000(ParentRunner.java:58<span style="color: #000000;">)
at org.junit.runners.ParentRunner$</span>2.evaluate(ParentRunner.java:268<span style="color: #000000;">)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:</span>61<span style="color: #000000;">)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:</span>71<span style="color: #000000;">)
at org.junit.runners.ParentRunner.run(ParentRunner.java:</span>363<span style="color: #000000;">)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:</span>174<span style="color: #000000;">)
at org.junit.runner.JUnitCore.run(JUnitCore.java:</span>137<span style="color: #000000;">)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:</span>68<span style="color: #000000;">)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:</span>47<span style="color: #000000;">)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:</span>242<span style="color: #000000;">)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:</span>70<span style="color: #000000;">)
Caused by: java.lang.IllegalArgumentException
at org.springframework.asm.ClassReader.
at org.springframework.asm.ClassReader.
at org.springframework.asm.ClassReader.
at org.springframework.core.type.classreading.SimpleMetadataReader.
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80<span style="color: #000000;">)
at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:101<span style="color: #000000;">)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:76<span style="color: #000000;">)
at org.springframework.context.annotation.ConfigurationClassUtils.checkConfigurationClassCandidate(ConfigurationClassUtils.java:70<span style="color: #000000;">)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor
.java:253<span style="color: #000000;">)
at org.springframework.context.annotation.ConfigurationClassPostProcessor
.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:223<span style="color: #000000;">)
at org.springframework.context.support.AbstractApplicationContext.invokebeanfactoryPostProcessors(AbstractApplicationContext.java:630<span style="color: #000000;">)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461<span style="color: #000000;">)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:106<span style="color: #000000;">)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:57<span style="color: #000000;">)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader
.delegateLoading(AbstractDelegatingSmartContextLoader.java:100<span style="color: #000000;">)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader
.loadContext(AbstractDelegatingSmartContextLoader.java:248<span style="color: #000000;">)
at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:124<span style="color: #000000;">)
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:148<span style="color: #000000;">)
... 23 more
spring 整合junit
<span style="color: #0000ff;">import<span style="color: #000000;"> org.junit.runner.RunWith;
<span style="color: #0000ff;">import<span style="color: #000000;"> org.springframework.test.context.ContextConfiguration;
<span style="color: #0000ff;">import<span style="color: #000000;"> org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
<span style="color: #0000ff;">import<span style="color: #000000;"> javax.annotation.Resource;
@RunWith(SpringJUnit4ClassRunner.<span style="color: #0000ff;">class<span style="color: #000000;">)
@ContextConfiguration("classpath:applicationContext.xml"<span style="color: #000000;">)
<span style="color: #0000ff;">public <span style="color: #0000ff;">class<span style="color: #000000;"> OrderDaoTest {
@Resource(name = "orderDao"<span style="color: #000000;">)
<span style="color: #0000ff;">private<span style="color: #000000;"> OrderDao orderDao;
@Test
</span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> run() {
<span style="color: #008000;">//<span style="color: #008000;"> ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
<span style="color: #008000;">//<span style="color: #008000;"> orderDao = (OrderDao) context.getBean("orderDao");
<span style="color: #0000ff;">this<span style="color: #000000;">.orderDao.save();
<span style="color: #0000ff;">this<span style="color: #000000;">.orderDao.find();
}
}
applicationContext.xml
<span style="color: #0000ff;"></
<span style="color: #800000;">beans<span style="color: #0000ff;">>我使用的是IDE是Idea,可以通过下面的方式进行修改
File->Project Structure->Project
修改为
到此解决
原文链接:https://www.f2er.com/java/191598.html