0

I have a project that is runing on eclipse but when i make "java -jar" it gives this error:

 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

When I make "java -version" the output is:

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)

What am I doing wrong?

Vikas Sharma
  • 745
  • 9
  • 19
  • Upgrade your spring version or use the same JDK from inside eclipse. – M. Deinum Nov 24 '15 at 11:07
  • The JVM used does not say anything about cour compiled bytecode. Possibly your code or some part of it was compile with a target version less than 1.5. This is just an educated guess, tough, because I cannot see your code. You could inspect it with `javap` from the JDK. – kriegaex Nov 24 '15 at 20:48

5 Answers5

3

@MaggieX isn't wrong - you are running into an old version of Spring that has an if {} statement that knows about Java 1.7 but not Java 1.8. It assumes if it cannot match 1.5, 1.6, or 1.7 that you are running Java 1.4.

So, downgrading to 1.7 is a workaround. Upgrading the Spring version is a fix. There are other answered questions on here where somebody added Java 1.8 support by rebuilding the Spring 2.5 jars from source. cf. https://stackoverflow.com/a/32487035

Community
  • 1
  • 1
Bill McGonigle
  • 215
  • 1
  • 9
0

I guess you're using Maven. Maybe you're missing some aspectj libraries?

Try adding this to your 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>
sschuberth
  • 28,386
  • 6
  • 101
  • 146
Abdelhak
  • 8,299
  • 4
  • 22
  • 36
  • Thank you for your help but that didn't work. The only solution that i found is to remove the aop dependecies and remove it from the "Beans.xml" – Jp Felgueiras Nov 24 '15 at 11:35
0

maybe you could change you jdk version.I change my jdk version to 1.7,then the project can run right

Maggie X
  • 11
  • 1
0

I also got exact same error. What I noticed that when I set JAVA_HOME system variable to JDK version 1.8 I got the error mentioned by Jp Felgueiras and by switching to JDK version 1.7 my code works, so looks like there is some issue with old version of spring code, and this may well be because of the code is spring core org.springframework.core.JdkVersion.java, this code deals with JDK version 1.4(default), 1.5, 1.6 and 1.7. This means if your java version is not 1.5, 1.6 or 1.7 then it will be treated as 1.4 so you get the error suggesting to user java version of 1.5 or higher. Hope this will help anyone stumble upon this question

Rai
  • 136
  • 7
0

Hi please go to eclipse workspace/your project/.setting(hidden folder)/edit org.eclipse.wst.common.component java version 1.5 to 1.7 or higher

林大為
  • 1
  • 1