问题
I'm using JDeveloper and Weblogic 12c(12.1.3) and I want to create a job with XML using Spring Batch. When I deploy the project It shows me and error. I need to use this IDE because of some restrictions in my job, also, without using maven.
I've seen several example and I think my XML it's fine. I think the problem is related to weblogic (I had a similar issue) because I made the same test with the same project structure and libraries using Netbeans IDE and GlassFish Open Source Edition 4.1.1, and it works.
The libraries
aopalliance-1.0.jar
com.ibm.jbatch-tck-spi-1.0.jar
commons-logging-1.1.3.jar
hsqldb-2.3.3.jar
javax.batch-api-1.0.jar
jettison-1.2.jar
spring-aop-4.0.5.RELEASE.jar
spring-batch-core-3.0.5.RELEASE.jar
spring-batch-infrastructure-3.0.5.RELEASE.jar
spring-beans-4.0.5.RELEASE.jar
spring-context-4.0.5.RELEASE.jar
spring-core-4.0.5.RELEASE.jar
spring-expression-4.0.5.RELEASE.jar
spring-jdbc-4.0.5.RELEASE.jar
spring-retry-1.1.0.RELEASE.jar
spring-tx-4.0.5.RELEASE.jar
spring-web-4.0.5.RELEASE.jar
spring-webmvc-4.0.5.RELEASE.jar
xmlpull-1.1.3.1.jar
xpp3_min-1.1.4c.jar
xstream-1.4.7.jar
The error
<org.springframework.web.servlet.FrameworkServlet> <FrameworkServlet> <initServletBean> <Context initialization failed>
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobLauncherController': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.springframework.batch.core.Job batch.JobLauncherController.job; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'job': Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessAfterInstantiation(AutowiredAnnotationBeanPostProcessor.java:243)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:959)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:402)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:316)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:282)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:126)
at javax.servlet.GenericServlet.init(GenericServlet.java:240)
My application context XML is this:
testBatch-servlet.xml
<beans:beans xmlns="http://www.springframework.org/schema/batch"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
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-3.0.xsd http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="batch"/>
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/"/>
<beans:property name="suffix" value=".jsp"/>
</beans:bean>
<beans:bean id="transactionManager"
class="org.springframework.batch.support.transaction.ResourcelessTransactionManager"></beans:bean>
<beans:bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<beans:property name="driverClassName" value="oracle.jdbc.OracleDriver"/>
<beans:property name="url" value="jdbc:oracle:thin:@//localhost:1521/xe"/>
<beans:property name="username" value="system"/>
<beans:property name="password" value="1234"/>
</beans:bean>
<beans:bean id="jobRepository" class="org.springframework.batch.core.repository.support.SimpleJobRepository">
<beans:constructor-arg>
<beans:bean class="org.springframework.batch.core.repository.dao.MapJobInstanceDao"/>
</beans:constructor-arg>
<beans:constructor-arg>
<beans:bean class="org.springframework.batch.core.repository.dao.MapJobExecutionDao"/>
</beans:constructor-arg>
<beans:constructor-arg>
<beans:bean class="org.springframework.batch.core.repository.dao.MapStepExecutionDao"/>
</beans:constructor-arg>
<beans:constructor-arg>
<beans:bean class="org.springframework.batch.core.repository.dao.MapExecutionContextDao"/>
</beans:constructor-arg>
</beans:bean>
<beans:bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<beans:property name="jobRepository" ref="jobRepository"/>
<beans:property name="taskExecutor">
<beans:bean class="org.springframework.core.task.SimpleAsyncTaskExecutor"/>
</beans:property>
</beans:bean>
<beans:bean id="myTasklet" class="batch.MyTasklet"></beans:bean>
<job id="job" job-repository="jobRepository">
<step id="test" >
<tasklet ref="myTasklet"/>
</step>
</job>
</beans:beans>
any ideas?
回答1:
I think you must use Filtering Classloading including the version of Spring you need.
http://docs.oracle.com/cd/E12839_01/web.1111/e13706/classloading.htm
If it is a war file then add true to weblogic.xml
That version is supported in WLS 12.1.3 :
WLS 12.1.3 Spring Framework versions 3.0.x, 3.1.x, and 4.0.x (note that version 3.2.x is not supported) (not-supported doesn't mean won't work).
回答2:
This is a workaround if I don't want to touch my weblogic.xml, but I can't use the new features of Spring Batch.
I have to use Spring Batch 2.2.7 to work with Weblogic 12.1.3, I created again a project with maven to find the dependencies. So the dependencies should be as follows:
aopalliance-1.0.jar
commons-logging-1.1.3.jar
jettison-1.1.jar
spring-aop-3.2.9.RELEASE.jar
spring-batch-core-2.2.7.RELEASE.jar
spring-batch-infrastructure-2.2.7.RELEASE.jar
spring-beans-3.2.9.RELEASE.jar
spring-context-3.2.9.RELEASE.jar
spring-core-3.2.9.RELEASE.jar
spring-expression-3.2.9.RELEASE.jar
spring-retry-1.0.2.RELEASE.jar
spring-tx-3.2.9.RELEASE.jar
spring-web-3.2.9.RELEASE.jar
spring-webmvc-3.2.9.RELEASE.jar
xpp3_min-1.1.4c.jar
xstream-1.3.jar
I hope there is a supported version of Spring Batch soon. I found that Weblogic already supports Spring but I don't know in what level.
来源:https://stackoverflow.com/questions/33289153/error-creating-job-in-spring-batch