java - Spring boot spring.batch.job.enabled=false not able to recognize -
i tried spring.batch.job.enabled=false
in application.properties , -dspring.batch.job.enabled=false
when running jar file.
however @enablebatchprocessing
automatically start running batch jobs on application start. how can debug such scenario?
testconfiguration.class
@configuration @enablebatchprocessing public class testconfiguration {...}
mainapplication
@componentscan("com.demo") @enableautoconfiguration public class mainapplication { public static void main(string[] args) throws beansexception, jobexecutionalreadyrunningexception, jobinstancealreadycompleteexception, jobparametersinvalidexception, interruptedexception, jobrestartexception { configurableapplicationcontext ctx = springapplication.run(testconfiguration.class, args); ...}
pom.xml using dependency spring boot , not parent
<dependencymanagement> <dependencies> <!-- import dependecy spring boot here--> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-parent</artifactid> <version>1.2.4.release</version> <type>pom</type> <scope>import</scope> </dependency>
i able know whats going on, using custom reader/processor/writer. when springboot application starts try dependency injection of custom beans beans have written application logic.
example
** testconfiguration.class**
@configuration @enablebatchprocessing public class testconfiguration { @bean @conditional(employee.class) public itemwriter<employee> writer_employee(datasource datasource) throws ioexception { flatfileitemwriter<employee> writer = new flatfileitemwriter<employee>(); writer.setresource(new filesystemresource(financereportutil.createfile("employee.csv"))); writer.setheadercallback(new flatfileheadercallback() { @override public void writeheader(writer writer) throws ioexception { writer.write("id, name"); } }); delimitedlineaggregator<employee> dellineagg = new delimitedlineaggregator<employee>(); dellineagg.setdelimiter(","); beanwrapperfieldextractor<employee> fieldextractor = new beanwrapperfieldextractor<employee>(); fieldextractor.setnames(new string[]{"id", "name"}); dellineagg.setfieldextractor(fieldextractor); writer.setlineaggregator(dellineagg); return writer; } @bean @conditional(manager.class) public itemwriter<person> writer_manager(datasource datasource) throws ioexception { // same logic employee } // has job , step etc. }
it create file spring.batch.job.enabled=false, overcome have created custom logic inject beans or not below
application.properties
# all, manager, employee person=manager
managercondition.class
public class managercondition implements condition { @override public boolean matches(conditioncontext context, annotatedtypemetadata metadata) { string person= context.getenvironment().getproperty("person"); return person.equals("manager"); }
Comments
Post a Comment