Reputation: 768
I am developing an application using Spring Batch in eclipse
Error I while starting the server is
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.......
My xml file used to config spring batch is
<?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="[email protected]"/>
<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>
Now the problem lies in xmlns part at the top of this config file.
In this config file the last bean I declared notificationController
tries to refer the bean named dispatchMailsJob
which is the first bean declared above but is unable to recognize it.
I am struck on for days. This is my second project in spring batch and I remember that the same issue consumed days in my first project also. (I now don't have access to the code of my first project)
Kindly help me out with what exactly should I write in the xmlns schema part
The spring related libraries I am using are
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
Upvotes: 1
Views: 2395
Reputation: 18403
Probably you need scope="step"
for beans using late-binding (#{jobParameters[...]}
for example); spring can't create job bean because it can't resolve batch-related spEL expressions
Upvotes: 1