标签: spring-batch

如何从Spring Batch中的ItemReader访问作业参数?

这是我的一部分job.xml:

<job id="foo" job-repository="job-repository">
  <step id="bar">
    <tasklet transaction-manager="transaction-manager">
      <chunk commit-interval="1"
        reader="foo-reader" writer="foo-writer"
      />
    </tasklet>
  </step>
</job>
Run Code Online (Sandbox Code Playgroud)

这是项目读者:

import org.springframework.batch.item.ItemReader;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component("foo-reader")
public final class MyReader implements ItemReader<MyData> {
  @Override
  public MyData read() throws Exception {
    //...
  }
  @Value("#{jobParameters['fileName']}")
  public void setFileName(final String name) {
    //...
  }
}
Run Code Online (Sandbox Code Playgroud)

这就是Spring Batch在运行时所说的:

Field or property 'jobParameters' cannot be found on object of 
type 'org.springframework.beans.factory.config.BeanExpressionContext'
Run Code Online (Sandbox Code Playgroud)

这有什么不对?在哪里可以阅读Spring 3.0中有关这些机制的更多信息?

java spring spring-batch

67
推荐指数
5
解决办法
10万
查看次数

我们如何在Spring Batch的作业的不同步骤之间共享数据?

深入研究Spring Batch,我想知道如何在作业的不同步骤之间共享数据?

我们可以使用JobRepository吗?如果是的话,我们怎么做?

有没有其他方法可以做到/达到同样的目的?

spring-batch

56
推荐指数
7
解决办法
8万
查看次数

如何开始使用Spring Batch?

我正在尝试学习Spring Batch,但启动指南非常令人困惑.评论喜欢

通过检查org.springframework.batch.sample包中的单元测试(在src/main/java中)和src/main/resources/jobs中的配置,可以很好地了解如何设置作业.

并不完全有用.另外我发现Sample项目非常复杂(17个非空命名空间,109个类)!有没有一个更简单的地方开始使用Spring Batch?

spring-batch

48
推荐指数
5
解决办法
4万
查看次数

无法配置DataSource:未指定'url'属性,也无法配置嵌入数据源

我正在使用MongoDB 开发Spring Boot Batch示例,并且已经启动了Mongod服务器

当我启动我的应用程序时,我收到以下错误.

这个问题有什么指针吗?

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class


Action:

Consider the following:
    If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
    If you have database settings to be loaded from a particular profile you may need to activate it (no profiles …
Run Code Online (Sandbox Code Playgroud)

spring spring-batch spring-boot

48
推荐指数
13
解决办法
13万
查看次数

如何将异常的集合作为根本原因传递?

某种方法myMethod调用多个并行执行并等待其终止。

这些并行执行可以例外完成。因此myMethod获得一个例外列表。

我想将异常列表作为根本原因进行传递,但根本原因可能只是单个异常。当然,我可以创建自己的异常来实现所需的功能,但是我想知道Java,Spring或Spring Batch是否具有类似这样的功能。

java spring exception spring-batch

44
推荐指数
2
解决办法
1403
查看次数

如何以编程方式覆盖Spring-boot application.properties

我有来自外部配置web-service的jdbc属性文件在spring boot中为了设置mysql道具,将它们添加到application.properties很容易:

spring.datasource.url=jdbc:mysql://localhost/mydb
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
Run Code Online (Sandbox Code Playgroud)

我怎么能在我的应用程序中重写那些程序?

Spring-batch道具同样如此:

database.driver=com.mysql.jdbc.Driver
database.url=jdbc:mysql://localhost/mydv
database.username=root
database.password=root
Run Code Online (Sandbox Code Playgroud)

spring spring-batch spring-batch-admin spring-boot

43
推荐指数
8
解决办法
5万
查看次数

Spring Boot如何运行批处理作业

我按照这个样本进行Spring Batch with Boot.

运行main方法时,将执行作业.这样我就无法弄清楚如何控制作业执行.例如,您如何安排作业,或访问作业执行或设置作业参数.

我试着注册我自己的JobLauncher

@Bean
public JobLauncher jobLauncher(JobRepository jobRepo){
    SimpleJobLauncher simpleJobLauncher = new SimpleJobLauncher();
    simpleJobLauncher.setJobRepository(jobRepo);
    return simpleJobLauncher;
}
Run Code Online (Sandbox Code Playgroud)

但是当我尝试在main方法中使用它时:

public static void main(String[] args) {
    ConfigurableApplicationContext ctx = SpringApplication.run(Application.class, args);    
    JobLauncher jobLauncher = ctx.getBean(JobLauncher.class);
    //try catch removed for readability
    jobLauncher.run(ctx.getBean(Job.class), new JobParameters());   
}
Run Code Online (Sandbox Code Playgroud)

加载上下文后再次执行作业,JobInstanceAlreadyCompleteException当我尝试手动运行时,我得到了该作业.有没有办法阻止自动执行作业?

java spring spring-batch spring-boot

41
推荐指数
1
解决办法
3万
查看次数

Spring-Batch没有将元数据保存到数据库?

我想创建一个spring-batch作业,但我想在没有任何数据库持久性的情况下运行它.不幸的是,spring-batch需要以metadata某种方式将ob作业周期写入数据库,从而促使我至少提供某种db与transactionmanager和entitymanager.

是否可以阻止元数据并独立于txmanagers和数据库运行?

更新:

ERROR org.springframework.batch.core.job.AbstractJob: Encountered fatal error executing job
java.lang.NullPointerException
    at org.springframework.batch.core.repository.dao.MapJobExecutionDao.synchronizeStatus(MapJobExecutionDao.java:158) ~[spring-batch-core-3.0.1.RELEASE.jar:3.0.1.RELEASE]
    at org.springframework.batch.core.repository.support.SimpleJobRepository.update(SimpleJobRepository.java:161) ~[spring-batch-core-3.0.1.RELEASE.jar:3.0.1.RELEASE]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_51]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_51]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_51]
    at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_51]
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) ~[spring-aop-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) ~[spring-aop-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98) ~[spring-tx-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262) ~[spring-tx-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95) ~[spring-tx-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) ~[spring-aop-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at com.sun.proxy.$Proxy134.update(Unknown Source) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_51]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_51]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_51]
    at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_51]
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) ~[spring-aop-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) …
Run Code Online (Sandbox Code Playgroud)

java spring spring-batch

39
推荐指数
7
解决办法
5万
查看次数

什么相当于Python的Celery Java项目?

我试图找到相当于Java环境的Celery项目,我已经看过Spring Batch,但是对于分布式任务队列有没有更好的选择.

谢谢.

python java batch-processing spring-batch celery

35
推荐指数
3
解决办法
2万
查看次数

在Spring Batch中使用多个DataSource

我试图在Spring Batch中配置几个数据源.在启动时,Spring Batch抛出以下异常:

To use the default BatchConfigurer the context must contain no more thanone DataSource, found 2

批量配置的代码段

@Configuration
@EnableBatchProcessing 
public class BatchJobConfiguration {

    @Primary
    @Bean(name = "baseDatasource")
    public DataSource dataSource() {
         // first datasource definition here
    }
    @Bean(name = "secondaryDataSource")
    public DataSource dataSource2() {
         // second datasource definition here
    }
    ...
}
Run Code Online (Sandbox Code Playgroud)

不知道为什么我看到这个异常,因为我已经看到一些基于xml的Spring批处理配置声明了多个数据源.我使用Spring Batch核心版本3.0.1.RELEASE与Spring Boot版本1.1.5.RELEASE.任何帮助将不胜感激.

java spring datasource spring-batch

33
推荐指数
2
解决办法
3万
查看次数