无法解析对bean MapExecutionContextDao的引用

时间:2018-09-24 07:42:13

标签: java spring spring-batch

我是Spring的新手,在尝试将我们的项目从Java 6升级到Java 8时遇到了此错误。

    00:51:42,543 ERROR main CommandLineJobRunner:355 - Job Terminated in error: Unexpected exception parsing XML document from class path resource [app-c
ontext/bprpp-context.xml]; nested exception is java.lang.IllegalStateException: Context namespace element 'annotation-config' and its parser class [o
rg.springframework.context.annotation.AnnotationConfigBeanDefinitionParser] are only available on JDK 1.5 and higher
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [app-context/bprpp
-context.xml]; nested exception is java.lang.IllegalStateException: Context namespace element 'annotation-config' and its parser class [org.springfra
mework.context.annotation.AnnotationConfigBeanDefinitionParser] are only available on JDK 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:12
3)
        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 org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:282)
        at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:574)
Caused by: java.lang.IllegalStateException: Context namespace element 'annotation-config' and its parser class [org.springframework.context.annotatio
n.AnnotationConfigBeanDefinitionParser] are only available on JDK 1.5 and higher
        at org.springframework.context.config.ContextNamespaceHandler$1.parse(ContextNamespaceHandler.java:65)
        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:13
5)
        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)
        ... 15 more
2018-09-20 00:51:42 - ***** step050 - java rc=1

我已阅读here来解决此问题,请使用Java 7或升级Spring版本。 Java 7不会这样做,因为我的目标是升级到Java 8,所以我尝试将Spring版本从2.1.9升级到4.0.0,但出现以下错误:

14:45:27,006 ERROR main CommandLineJobRunner:370 - Job Terminated in error: Error creating bean with name 'jobRepository' defined in class path resource [app-context/bprpp-memory-context.xml]: Cannot resolve reference to bean 'executionContextDao' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'executionContextDao' defined in class path resource [app-context/bprpp-memory-context.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.batch.core.repository.dao.MapExecutionContextDao]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/core/DecoratingProxy
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobRepository' defined in class path resource [app-context/bprpp-memory-context.xml]: Cannot resolve reference to bean 'executionContextDao' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'executionContextDao' defined in class path resource [app-context/bprpp-memory-context.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.batch.core.repository.dao.MapExecutionContextDao]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/core/DecoratingProxy
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
    at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:616)
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:148)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1035)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:939)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:292)
    at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:596)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'executionContextDao' defined in class path resource [app-context/bprpp-memory-context.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.batch.core.repository.dao.MapExecutionContextDao]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/core/DecoratingProxy
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:997)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:943)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
    ... 18 more
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.batch.core.repository.dao.MapExecutionContextDao]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/core/DecoratingProxy
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:162)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:76)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:990)
    ... 26 more
Caused by: java.lang.NoClassDefFoundError: org/springframework/core/DecoratingProxy
    at org.springframework.aop.framework.AopProxyUtils.completeProxiedInterfaces(AopProxyUtils.java:135)
    at org.springframework.aop.framework.JdkDynamicAopProxy.getProxy(JdkDynamicAopProxy.java:121)
    at org.springframework.aop.framework.JdkDynamicAopProxy.getProxy(JdkDynamicAopProxy.java:113)
    at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:97)
    at org.springframework.batch.support.transaction.TransactionAwareProxyFactory.createInstance(TransactionAwareProxyFactory.java:154)
    at org.springframework.batch.support.transaction.TransactionAwareProxyFactory.createAppendOnlyTransactionalMap(TransactionAwareProxyFactory.java:170)
    at org.springframework.batch.core.repository.dao.MapExecutionContextDao.<init>(MapExecutionContextDao.java:41)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
    ... 28 more
Caused by: java.lang.ClassNotFoundException: org.springframework.core.DecoratingProxy
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 40 more

以下是相关文件:

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.xcel.brp</groupId>
    <artifactId>BRP-BATCH</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>BRP-BATCH</name>
    <!-- <url>http://maven.apache.org</url> -->

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <spring.version>3.1.1.RELEASE</spring.version>
        <!-- <junit.version>4.4</junit.version> -->
        <junit.version>4.12</junit.version>
        <snowdrop.version>2.0.0.Final</snowdrop.version>
        <commons-logging.version>1.1.1</commons-logging.version>
        <cxf.version>2.4.6</cxf.version>
        <slf4j.version>1.5.8</slf4j.version>
        <spp.version>1.0-SNAPSHOT</spp.version>
        <log4j.version>1.2.16</log4j.version>
        <!-- <spring-batch.version>2.1.9.RELEASE</spring-batch.version> -->
    </properties>


    <dependencies>
        <dependency>
            <groupId>org.springframework.batch</groupId>
            <artifactId>spring-batch-core</artifactId>
            <!-- <version>2.1.9.RELEASE</version> -->
            <version>4.0.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.batch</groupId>
            <artifactId>spring-batch-test</artifactId>
            <!-- <version>${spring-batch.version}</version> -->
            <version>4.0.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.ws</groupId>
            <artifactId>spring-oxm</artifactId>
            <version>1.5.10</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>${commons-logging.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.ws</groupId>
            <artifactId>spring-oxm-tiger</artifactId>
            <version>1.5.10</version>
        </dependency>

    </dependencies>
    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.java</include>
                    <include>**/*.gwt.xml</include>
                </includes>
            </resource>
        </resources>
    </build>

</project>

bprpp-memory-context.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd 
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> 

    <bean id="jobRepository" 
          class="org.springframework.batch.core.repository.support.SimpleJobRepository">
        <constructor-arg index="0" ref="jobInstanceDao"      />
        <constructor-arg index="1" ref="jobExecutionDao"     />
        <constructor-arg index="2" ref="stepExecutionDao"    />
        <constructor-arg index="3" ref="executionContextDao" />
    </bean>
    <bean id="jobInstanceDao" 
          class="org.springframework.batch.core.repository.dao.MapJobInstanceDao" />

    <bean id="jobExecutionDao" 
          class="org.springframework.batch.core.repository.dao.MapJobExecutionDao" />

    <bean id="stepExecutionDao" 
          class="org.springframework.batch.core.repository.dao.MapStepExecutionDao" />

    <bean id="executionContextDao" 
          class="org.springframework.batch.core.repository.dao.MapExecutionContextDao" />

    <bean id="jobExplorer" 
          class="org.springframework.batch.core.explore.support.SimpleJobExplorer">
        <constructor-arg index="0" ref="jobInstanceDao"      />
        <constructor-arg index="1" ref="jobExecutionDao"     />
        <constructor-arg index="2" ref="stepExecutionDao"    />
        <constructor-arg index="3" ref="executionContextDao" />
    </bean>

    <bean id="jobLauncher" 
          class="org.springframework.batch.core.launch.support.SimpleJobLauncher" >     
        <property name="jobRepository" ref="jobRepository" />        
    </bean>

    <bean id="transactionManager" 
          class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" /> 

</beans>

1 个答案:

答案 0 :(得分:0)

您的问题是使用Maven BOM表解决的典型问题。对于春季项目,我建议您使用Spring Boot BOM而不是导入依赖关系并手动指定版本。此BOM将带来众所周知的弹簧依赖关系,可以很好地协同工作。即使您不使用Spring Boot,也可以使用此BOM。

在您的情况下,如果您使用的是Spring Boot版本2.0.5.RELEASE,它将带来spring Batch 4.0.1.RELEASE和spring Framework 5.0.9.RELEASE。

希望这会有所帮助。