This week's book giveaway is in the Android forum.
We're giving away four copies of Learning Java by Building Android Games and have Jean-Marcel Belmont on-line!
See this thread for details.
Win a copy of Learning Java by Building Android Games this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Injection of autowired dependencies failed  RSS feed

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi All,

I am getting the following error while starting my weblogic server:
2013-09-13 17:36:15 INFO SimpleStepHandler:133 - Executing step: [step1]
2013-09-13 17:36:15 ERROR AbstractStep:212 - Encountered an error executing the step
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.batchReader': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.abc.batch.dao.FileMetadataDAO com.abc.batch.reader.SampleReader.metaData; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'jdbcFileMetaDataDAO' is defined
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:332)
at org.springframework.batch.core.scope.StepScope.get(StepScope.java:150)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:328)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:33)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:184)
at $Proxy64.read(Unknown Source)
at org.springframework.batch.core.step.item.SimpleChunkProvider.doRead(SimpleChunkProvider.java:90)
at org.springframework.batch.core.step.item.SimpleChunkProvider.read(SimpleChunkProvider.java:148)
at org.springframework.batch.core.step.item.SimpleChunkProvider$1.doInIteration(SimpleChunkProvider.java:108)

My classes and xml files are as follows:

*******************************************************
Sample Reader
*********************
package com.abc.batch.reader;


public class SampleReader implements ItemReader<String> {

private static final Logger LOGGER = LoggerFactory.getLogger(SampleReader.class);

// @Autowired
//private PhoneOptDAO phoneDAO;

@Autowired
@Qualifier("fileMetadataDAO")
private FileMetadataDAO metaData;


public String read() throws Exception, UnexpectedInputException,
ParseException, NonTransientResourceException {

try {

// Directory path here


LOGGER.debug("some message to log");

LOGGER.info("**********************some message to log : : : "+path);

String files = null;
List<String> dataList = new ArrayList<String>();
File folder = new File(path);
File[] listOfFiles = folder.listFiles();

if(listOfFiles!=null){
if(listOfFiles.length>0){

for (int i = 0; i < listOfFiles.length; i++)
{

if (listOfFiles[i].isFile())
{
files = listOfFiles[i].getName();
if (files.endsWith(".txt") || files.endsWith(".TXT"))
{
System.out.println(files);

int status = updateMetaData(files, "N", "I");


} catch (SQLException e) {

System.out.println(e.getMessage());

}

return null;
}


private int updateMetaData(String fileName, String pStat, String newStat){
int updstatus =0;


//ApplicationContext context =
//new ClassPathXmlApplicationContext("Spring-Module.xml");

//FileMetadataDAO metaData = (FileMetadataDAO) context.getBean("fileMetadataDAO");

FileMetadata meta = new FileMetadata(fileName, pStat, newStat);

updstatus = metaData.updateMetadata(meta);

System.out.println("file name: "+fileName +" updated in Metadata table!" +updstatus);

return updstatus;

}
}

*******************************************************************************
launch-context.xml
*******************************

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">

<context:component-scan base-package="com.abc.batch" />

<import resource="../../../../Spring-Module.xml"/>

<context:property-placeholder location="classpath:batch-default.properties"/>

<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg ref="dataSource" />
</bean>

<bean id="jobRegistry"
class="org.springframework.batch.core.configuration.support.MapJobRegistry" />

<bean class="org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor">
<property name="jobRegistry" ref="jobRegistry" />
</bean>

<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<constructor-arg ref="dataSource" />
</bean>

<bean id="jobRepository"
class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
<property name="transactionManager" ref="transactionManager" />
</bean>

<batch:job-repository id="jobRepository" />

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

<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${batch.jdbc.driver}" />
<property name="url" value="${batch.jdbc.url}" />
<property name="username" value="${batch.jdbc.user}" />
<property name="password" value="${batch.jdbc.password}" />
<property name="maxActive" value="${batch.jdbc.max.active}" />
</bean>

<jdbc:initialize-database data-source="dataSource" enabled="${batch.data.source.init}">
<jdbc:script location="${batch.schema.script}" />
</jdbc:initialize-database>

</beans>

*****************************************************************************

Spring-Module.xml
****************************
<beans xmlns="http://www.springframework.org/schema/beans"
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">

<import resource="database/Spring-Datasource.xml"/>
<import resource="metadata/Spring-MetaData.xml"/>

</beans>

*******************************************************************************
Spring-Metadata.xml
**********************
<beans xmlns="http://www.springframework.org/schema/beans"
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">

<bean id="fileMetadataDAO" class="com.abc.batch.dao.impl.JdbcFileMetaDataDAO">
<constructor-arg index="0" ref="dataSource"/>
</bean>

</beans>

****************************************************************

JDBCFileMetaDataDAO.java
*********************************

package com.abc.batch.dao.impl;

@Service
public class JdbcFileMetaDataDAO extends JdbcDaoSupport implements FileMetadataDAO

{
@Autowired
JdbcFileMetaDataDAO(DataSource dataSource){
setDataSource(dataSource);
}


public int findTotalCustomer(){

String sql = "SELECT COUNT(*) FROM FILE_METADATA";

int total = getJdbcTemplate().queryForInt(sql);

return total;
}

@Override
public int updateMetadata(FileMetadata m1) {

String sql = "update FILE_METADATA set status=?, bby_aud_ts= sysdate where file_name=? and status = ?";

int rows= getJdbcTemplate().update(sql, new Object[] {m1.getNewStatus(),m1.getFile(),m1.getPrevStatus()});

return rows;
}

@Override
public void insert(FileMetadata file) {

String sql = "Insert into file_metadata (FILE_ID,FILE_NAME,BBY_CR_TS,BBY_AUD_TS,STATUS) values "
+ "(999,?,to_date('14-AUG-13','DD-MON-RR'),null,?)";

getJdbcTemplate().update(sql, new Object[] {file.getFile(),file.getNewStatus()});

}

@Override
public FileMetadata findByFileName(String title) {
// TODO Auto-generated method stub
return null;
}



}

********************************************
batch-feed-context.xml
*****************
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:util="http://www.springframework.org/schema/util" xmlns:int-file="http://www.springframework.org/schema/integration/file"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
http://www.springframework.org/schema/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file-2.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd">

<import resource="launch-context.xml" />

<!-- Jobs -->
<bean id="scheduledLauncher" class="com.abc.batch.scheduler.ScheduledLauncher">
<property name="jobLauncher" ref="jobLauncher" />
</bean>
<task:scheduler id="scheduler" />
<task:scheduled-tasks scheduler="scheduler">
<task:scheduled ref="scheduledLauncher" method="launch"
cron="0/15 * * * * ?" />

<!-- cron="0 0 3,15 * * ?" />-->
<!-- cron="0/15 * * * * ?" />-->
<!-- cron="0 35 16 ? * MON-FRI" /> -->
<!-- cron="0 0 3,15 * * ?" /> -->

</task:scheduled-tasks>

<job id="sampleBatchJob" xmlns="http://www.springframework.org/schema/batch"
job-repository="jobRepository">
<step id="step1">
<tasklet>
<chunk reader="batchReader" processor="batchProcessor"
writer="batchWriter" commit-interval="10">
</chunk>
</tasklet>
</step>
</job>

<!-- Item Readers -->

<bean id="batchReader"
class="com.abc.batch.reader.SampleReader"
scope="step">
</bean>

<!-- Item Processors -->

<bean id="batchProcessor"
class="com.abc.batch.processor.SampleProcessor"/>

<!-- Item Writers -->
<bean id="batchWriter"
class="com.abc.batch.writer.SampleWriter"
scope="step"/>


******************************************************

ANy help is highly appreciated

</beans>

 
author & internet detective
Marshal
Posts: 38650
675
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could change
<bean id="fileMetadataDAO" class="com.abc.batch.dao.impl.JdbcFileMetaDataDAO">
to
<bean id="jdbcFileMetadataDAO" class="com.abc.batch.dao.impl.JdbcFileMetaDataDAO">

Which would fix the error. I don't see anything asking to wire in jdbcFileMetadataDAO though. My guess is either Spring is looking at different (old) code or something is autowiring by name that I'm not seeing.
 
Beth Candida
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am still getting the same error even after making the bean ID chnange. I even did a maven clean install + update maven project.
I am not sure why my code is braeking on server restart.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 38650
675
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Beth,
How do you deploy your application? Install just jars it up and puts in your .m2 repository. It doesn't tell Tomcat (or whatever server) about it.
 
Beth Candida
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

I deploy my war file (created in target folder at the time maven install) of the application on the weblogic console.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!