作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在与 建立一个项目不使用 Spring Boot 的 Spring Batch .
创建 Spring 应用程序上下文后,所有作业都会执行。
我尝试添加 spring.batch.job.enbled=false
到 application.properties 以防止这种情况,但它仍然不起作用。
有没有其他方法可以阻止 Spring 在开始时执行作业?
主要类:
package com.project.batch;
import ...
@Configuration
@EnableBatchProcessing
@PropertySource("classpath:application.properties")
public class App {
public static void main(String [] args) throws JobParametersInvalidException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException {
System.out.println("starting main");
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.scan("com.project.batch");
context.refresh();
//JobParameters jobParameters = new JobParametersBuilder().toJobParameters();
//JobLauncher jobLauncher = context.getBean(JobLauncher.class);
//JobExecution execution = jobLauncher.run(context.getBean("loaderJob",Job.class),jobParameters);
System.out.println("finished!!");
}
}
package com.project.batch;
import ...
@Configuration
public class LoaderJobConfig {
@Autowired
private JobBuilderFactory jobBuilderFactory;
@Autowired
JdbcTemplate jdbcTemplate;
@Autowired
private StepBuilderFactory stepBuilderFactory;
@Bean
public Job loaderJob(Step step1) throws Exception {
System.out.println("Starting loaderJob");
...
}
}
spring.batch.job.enbled=false
spring.batch.job.names=
starting main
Nov 06, 2017 9:29:02 AM org.springframework.context.annotation.AnnotationConfigApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@306a30c7: startup date [Mon Nov 06 09:29:02 EST 2017]; root of context hierarchy
Nov 06, 2017 9:29:03 AM org.springframework.context.annotation.ConfigurationClassEnhancer intercept
WARNING: @Bean method ScopeConfiguration.stepScope is non-static and returns an object assignable to Spring's BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as @Autowired, @Resource and @PostConstruct within the method's declaring @Configuration class. Add the 'static' modifier to this method to avoid these container lifecycle issues; see @Bean Javadoc for complete details
Nov 06, 2017 9:29:03 AM org.springframework.context.annotation.ConfigurationClassEnhancer intercept
WARNING: @Bean method ScopeConfiguration.jobScope is non-static and returns an object assignable to Spring's BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as @Autowired, @Resource and @PostConstruct within the method's declaring @Configuration class. Add the 'static' modifier to this method to avoid these container lifecycle issues; see @Bean Javadoc for complete details
Nov 06, 2017 9:29:03 AM org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName
INFO: Loaded JDBC driver: org.postgresql.Driver
Starting loaderJob
found the value: [MER]
Completed loaderJob
finished!!
Process finished with exit code 0
最佳答案
Spring中提到的解决方案docs为我工作。我只是在 application.properties 中添加了一行,它会在启动时停止批处理作业的执行。
spring.batch.job.enabled=false
关于spring - 在没有 Spring Boot 的情况下创建上下文后防止 Spring Batch 自 Action 业触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47085330/
我是一名优秀的程序员,十分优秀!