我有一个在eclipse上运行的项目,但是当我使用" java -jar" 时会出现此错误:
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [Beans.xml]; nested
java.lang.IllegalStateException: AnnotationAwareAspectJAutoProxyCreator is only available on Java 1.5 and higher
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:420)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:113)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:80)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:123)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:422)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at pt.myCompany.myProduct.integrator.Integrator.init(Integrator.java:27)
at pt.myCompany.myProduct.integrator.jobs.RequstSentToProvider.execute(RequstSentToProvider.java:24)
at pt.myCompany.integrador.jobSchedule.RunRequstSentToProvider.main(RunRequstSentToProvider.java:10)
Caused by: java.lang.IllegalStateException: AnnotationAwareAspectJAutoProxyCreator is only available on Java 1.5 and higher
at org.springframework.aop.config.AopConfigUtils.getAspectJAnnotationAutoProxyCreatorClassIfPossible(AopConfigUtils.java:134)
at org.springframework.aop.config.AopConfigUtils.registerAspectJAnnotationAutoProxyCreatorIfNecessary(AopConfigUtils.java:99)
at org.springframework.aop.config.AopNamespaceUtils.registerAspectJAnnotationAutoProxyCreatorIfNecessary(AopNamespaceUtils.java:71)
at org.springframework.aop.config.AspectJAutoProxyBeanDefinitionParser.parse(AspectJAutoProxyBeanDefinitionParser.java:41)
at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:69)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1297)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1287)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:135)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:92)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:507)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:398)
... 16 more
当我&#34; java -version&#34; 时,输出为:
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)
我做错了什么?
答案 0 :(得分:2)
@MaggieX没有错 - 你正在遇到一个旧版本的Spring,它有一个知道Java 1.7而不是Java 1.8的if {}语句。它假设您运行Java 1.4时无法匹配1.5,1.6或1.7。
因此,降级到1.7是一种解决方法。升级Spring版本是一个修复。还有其他一些已回答的问题,有人通过从源代码重建Spring 2.5 jar来添加Java 1.8支持。比照https://stackoverflow.com/a/32487035
答案 1 :(得分:0)
我猜你正在使用Maven。
也许您错过了一些aspectj
个图书馆?
尝试将此添加到您的pom.xml
:
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.7.3</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.7.3</version>
</dependency>
答案 2 :(得分:0)
也许你可以改变你的jdk版本。我将我的jdk版本更改为1.7,然后项目可以正确运行
答案 3 :(得分:0)
我也得到完全相同的错误。我注意到当我将JAVA_HOME系统变量设置为JDK版本1.8时,我得到了Jp Felgueiras提到的错误并切换到JDK版本1.7我的代码工作,所以看起来旧版本的spring代码存在一些问题,这可能是好吧,因为代码是spring core org.springframework.core.JdkVersion.java,这段代码处理的是JDK 1.4版(默认),1.5,1.6和1.7。这意味着如果您的Java版本不是1.5,1.6或1.7,那么它将被视为1.4,因此您会收到建议用户使用1.5或更高版本的java版本的错误。希望这可以帮助任何人偶然发现这个问题
答案 4 :(得分:0)
您好请转到eclipse工作区/您的项目/ .setting(隐藏文件夹)/编辑org.eclipse.wst.common.component java版本1.5到1.7或更高版本