我正在eclipse中使用Spring Batch开发一个应用程序
启动服务器时出错
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'notificationController' defined in ServletContext
resource [/WEB-INF/springbatch-config.xml]: Cannot create inner bean
'com.confluence14.utility.Notifier#72372ef8' of type
[com.confluence14.utility.Notifier] while setting constructor argument;
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'com.confluence14.utility.Notifier#72372ef8' defined in
ServletContext resource [/WEB-INF/springbatch-config.xml]:
Cannot resolve reference to
bean 'dispatchMailsJob' while setting constructor argument; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'dispatchMailsJob': Cannot create inner bean '(inner bean)' of type
[org.springframework.batch.core.configuration.xml.SimpleFlowFactoryBean] while setting
bean property 'flow'; ......and so on.......
我用于配置spring批处理的xml文件是
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/batch
http://www.springframework.org/schema/batch/spring-batch-2.2.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
">
<batch:job id="dispatchMailsJob" restartable="false" job-repository="jobRepository">
<batch:step id="dispatchMailsStep">
<batch:tasklet>
<batch:chunk reader="mailIdReader" writer="mailWriter" commit-interval="10" />
</batch:tasklet>
</batch:step>
</batch:job>
<bean id="mailIdReader" class="org.springframework.batch.item.database.JdbcCursorItemReader">
<property name="dataSource" ref="myDataSource" />
<property name="sql" value="select #{jobParameters['tablename']}.user_id, login_credential.email
from #{jobParameters['tablename']}
inner join login_credential
on #{jobParameters['tablename']}.user_id = login_credential.user_id
where #{jobParameters['tablename']}.#{jobParameters['attribute.name']} = '#{jobParameters['attribute.value']}'
and #{jobParameters['tablename']}.mapping_type >= '#{jobParameters['mappingType']'};
" />
<property name="rowMapper">
<bean class="com.confluence14.utility.batch.MailIdRowMapper" />
</property>
</bean>
<bean id="mailWriter" class="com.confluence14.utility.batch.MailWriter">
<constructor-arg index="0" ref="mailer" />
<constructor-arg index="1" value="#{jobParameters['mail.text']}" />
<constructor-arg index="2" value="#{jobParameters['mail.subject']}" />
</bean>
<bean id="mailer" class="com.confluence14.utility.Mailer">
<constructor-arg index="0" ref="mailSender" />
</bean>
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="smtp.gmail.com"/>
<property name="port" value="25"/>
<property name="username" value="marg.ipicas@gmail.com"/>
<property name="password" value="todayisTGMC"/>
<property name="javaMailProperties">
<props>
<prop key="mail.transport.protocol">smtp</prop>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.starttls.enable">true</prop>
<prop key="mail.debug">true</prop>
</props>
</property>
</bean>
<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository" />
<property name="taskExecutor" ref="taskExecutor" />
</bean>
<bean id="jobRepository" class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
<property name="transactionManager" ref="transactionManager"/>
</bean>
<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="5" />
<property name="maxPoolSize" value="5" />
</bean>
<bean id="notificationController" class="com.confluence14.controller.NotificationController" >
<constructor-arg index="0">
<bean class="com.confluence14.utility.Notifier" >
<constructor-arg index="0" ref="jobLauncher" />
<constructor-arg index="1" ref="dispatchMailsJob" />
</bean>
</constructor-arg>
</bean>
</beans>
现在问题在于此配置文件顶部的xmlns部分。
在这个配置文件中,我声明的最后一个bean notificationController
尝试引用名为dispatchMailsJob
的bean,它是上面声明的第一个bean但无法识别它。
我被打了好几天。 这是我在春季批次的第二个项目,我记得同样的问题在我的第一个项目中消耗了几天。 (我现在无法访问我的第一个项目的代码)
请帮我解决一下我应该在xmlns架构部分写什么
我使用的弹簧相关库是
spring-aop-3.2.3.RELEASE.jar
spring-batch-core-2.2.3.RELEASE.jar
spring-batch-infrastructure-2.2.3.RELEASE.jar
spring-beans-3.2.3.RELEASE.jar
spring-context-3.2.5.RELEASE.jar
spring-context-support-3.2.5.RELEASE.jar
spring-core-3.2.3.RELEASE.jar
spring-expression-3.2.3.RELEASE.jar
spring-jdbc-3.2.3.RELEASE.jar
spring-orm-3.2.3.RELEASE.jar
spring-retry-1.0.2.RELEASE.jar
spring-tx-3.2.3.RELEASE.jar
spring-web-3.2.3.RELEASE.jar
spring-webmvc-3.2.3.RELEASE.jar
答案 0 :(得分:1)
对于使用后期绑定(例如scope="step"
)的bean,可能需要#{jobParameters[...]}
; spring无法创建作业bean,因为它无法解析与批处理相关的spEL表达式