Spring Batch: @Value is null when other annotations are not -
Spring Batch: @Value is null when other annotations are not -
i have java/spring application connects mongo database. application uses spring annotations throughout. have base of operations database class looks this:
public abstract class mongodatabase { @value("${db.url}") private string db_url; @value("${db.index}") private string db_index; public dbcollection createconnection() { seek { mongouri mongouri = new mongouri(db_url); db db = mongouri.connectdb(); db.authenticate(mongouri.getusername(), mongouri.getpassword()); homecoming db.getcollection(db_index); } grab (exception e) { e.printstacktrace(); } homecoming null; }
}
this works when connect through mvc way (@controller class autowired @service class autowired @service class (my dao) in turn loads connection this:
dbcollection coll = createconnection();
however, when effort access database spring batch job, @value's in base of operations class null. rest of annotations work (@autowired). have spring batch xml calls next runmejob:
@component public class runmejob extends quartzjobbean { private runmetask runmetask; public void setrunmetask(runmetask runmetask) { this.runmetask = runmetask; } protected void executeinternal(jobexecutioncontext context) throws jobexecutionexception { runmetask.batchrunner(); } }
this in turn calls runmetask:
@component public class runmetask { @autowired private accountservice accountservice; @autowired private scanservice scanservice; public void batchrunner() { jsonarray accounts = accountservice.getallaccounts(); hashset<string> uniqueaccounts = accountservice.getaccountprop(accounts, "name"); } }
from here autowired accountservice, connects base of operations database class , @value null. missing?
figured out- super simple. had property file mapped in mvc-dispatcher-servlet by:
<context:property-placeholder location="classpath:prop.properties" />
did not have in spring batch xml file. not sure why mvc-dispatcher isn't picked when batch job runs though?
spring spring-batch
Comments
Post a Comment