我正在使用 Spring Boot 2.0.4.RELEASE 版本,仅使用默认缓存提供程序启用缓存,不使用外部缓存提供程序。
我已经安排了一批在每天的特定时间运行。在其运行期间,涉及数据访问的某些方法调用被缓存并且工作正常。
现在我想在下次功能启动之前在预定时间释放所有缓存的项目。
我无法实现此功能。你们能否指导我一些想法或如何实施它的方法。
这就是我正在努力实现的。我有一个标记为 @Configuration 的 JobExecutionListener 类。我正在使用它的 afterJob 方法来清除所有缓存。
@Configuration
@JobScope
public class JobTwoExecutionListener implements JobExecutionListener {
private static final Logger logger = LoggerFactory.getLogger(JobTwoExecutionListener.class);
@Autowired
private CacheManager cacheManager;
@Override
public void beforeJob(JobExecution jobExecution) {
final String methodName = "beforeJob() : ";
logger.info(methodName + "called");
if(cacheManager == null) return;
logger.info(methodName + "CacheManager FOUND. Listing all the caches
before Job Run");
for(String name : cacheManager.getCacheNames()){
logger.info(methodName + "CACHE_NAME BEFORE JOB " + name);
}
}
@Override …Run Code Online (Sandbox Code Playgroud) 我遵循了Spring Batch 文档,该文档有效并且足够简单和平庸,但仍然无法弄清楚如何应用相同的技术从外部 API 获取 JSON 数据。据我了解,我必须使用JsonItemReaderBuilder并定义reader方法来返回实例,JsonItemReader如下所示:
@Configuration
@EnableBatchProcessing
public class BatchConfiguration {
@Autowired
public JobBuilderFactory jobBuilderFactory;
@Autowired
public StepBuilderFactory stepBuilderFactory;
@Bean
public JsonItemReader<Person> reader() {
return new JsonItemReaderBuilder<Person>()
.name("personItemReader")
.build();
}
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是如何替换.resource(new ClassPathResource("sample-data.csv"))上面示例中仅读取 CSV 文件的行?我想我必须传入 JSON 数据作为InputStream实例或类似的东西?我应该传入什么样的资源?谢谢。
我开发了一个 Spring Batch 项目,其中包括多个作业。
我的目的是将这些作业的日志写入单独的文件中。例如,当Job#1启动时,所有事件都将记录到job_1.log中,当Job#2启动时,其事件将记录到job_2.log中,依此类推。
在我的工作配置中,我使用了:
private static final Logger logger = LoggerFactory.getLogger(Job1.class);
Run Code Online (Sandbox Code Playgroud)
我还尝试按照此链接的指示配置 logback.xml 。但是,我不知道如何将MDC放入Spring Batch(MDC .put("logFileName", "Job1");
使用 Spring Batch 时有更好的方法解决我的问题吗?
我正在解析一个文件并创建一个字符串元素列表,并将其插入到我的表中。我试图设置一次插入 5 行的批量大小,但不知道如何在我的代码中使用.batchupdatein 代替.update
初始代码:
Tasklet 类定义有 3 个方法:
class Tasklet{
doBeforeStep(){
//Records a retrieved from the table.
}
doExecute(){
//It opens the file and reads the file.
//Does all the processing one by one and creates a 2 list of records to update into the database.
}
doAfterStep(){
//The 2 list of records(Entities) are saved into the 2 different tables database using its corresponding repository class. Example:
RepositoryClass.saveall(List containing 105,000 records) //using the CRUDRepository method
}
}
Run Code Online (Sandbox Code Playgroud)
面临的问题: 该文件包含 150,000 条记录,因此,在 doExecute() 方法之后,它在列表中存储了 …
我们正在与两个不同的团队开发两个项目。然而,这两个项目有一些共同点,例如,有共同的实体和存储库使用案例。如何在不使用代码复用的情况下管理两个项目中的单个实体/存储库?
注意:第一个项目是 spring-batch/spring cloud task 第二个项目是微服务项目
谢谢...
architecture spring-batch spring-boot microservices spring-cloud-task
大家好,我有一个正在运行的春季调度程序作业,它必须在谷歌云上运行,并按预定的时间间隔运行。
它与 docker-compose 本地部署完美配合。它会毫无问题地触发。
虽然它在谷歌云运行服务中本地工作正常,并且 CPU 节流关闭,使 CPU 始终保持 100% 开启,但它在第一次运行后就无法工作。
我将粘贴 docker 文件以供任何一次参考,但我很确定它工作正常
FROM maven:3-jdk-11-slim AS build-env
# Set the working directory to /app
WORKDIR /app
COPY pom.xml ./
COPY src ./src
COPY css-common ./css-common
RUN echo $(ls -1 css-common/src/main/resources)
# Build and create the common jar
RUN cd css-common && mvn clean install
# Build and the job
RUN mvn package -DskipTests
# It's important to use OpenJDK 8u191 or above that has container support enabled.
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds …Run Code Online (Sandbox Code Playgroud) spring-batch spring-scheduled spring-boot google-cloud-platform google-cloud-run
作为迁移到 Spring Batch 5.0 的一部分,文档称javax.*类已替换为jakarta.*. 但是,Spring Batch API 仍然引用javax..
这是一个带有 的示例JdbcCursorItemReader。
@Configuration
public class Config {
@Autowired
private jakarta.activation.DataSource dataSource;
@Bean
public ItemReader<T> reader() {
JdbcCursorItemReader<T> reader = new JdbcCursorItemReader<>();
// Requires javax's datasource and not Jarkata.
reader.setDataSource(dataSource);
}
}
Run Code Online (Sandbox Code Playgroud)
目前,我还没有看到在 Spring Batch 5 中读取数据库或从数据库读取数据的前进道路,除非有一些我可以参考的文档。我在新增功能或迁移指南中没有看到它。
我有一个非常简单的 Spring Boot 项目,其中包含 Spring Batch 5.0 和 CommmandLineRunner。有一项作业、一个步骤和一个仅打印“正在运行”的微线程。我遵循指示并期望工作能够开始和完成。
没有错误;正在创建批处理数据库表;正在创建 Job 和 Step beans。
它就是不运行。
我将不胜感激任何见解或帮助!
注意:如果我使用自动装配的 JobLauncher 从 CommandLineRunner 显式启动作业,则它可以正常工作。它只是不会自动启动作业(如承诺的那样)。
注意 2:删除@EnableBatchProcessing 没有什么区别。
代码如下
应用程序属性:
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost/postgres
spring.batch.jdbc.initialize-schema=always
spring.batch.job.enabled=true
Run Code Online (Sandbox Code Playgroud)
应用程序.java:
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost/postgres
spring.batch.jdbc.initialize-schema=always
spring.batch.job.enabled=true
Run Code Online (Sandbox Code Playgroud)
作业配置:
@SpringBootApplication
@EnableBatchProcessing
public class Application implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
public void run(String... args) throws Exception {
System.out.println("Starting...");
Thread.sleep(2000);
}
}
Run Code Online (Sandbox Code Playgroud)
小任务:
@Configuration
public class AbacusJobConfiguration {
Logger logger = LoggerFactory.getLogger(AbacusJobConfiguration.class);
@Bean …Run Code Online (Sandbox Code Playgroud) 是否有可能在春季批次中让一个读取器读取数据并将数据拆分为多个写入器以进行并行处理?
步骤: Reader:JdbcCursorItemReader读取100条记录10个并行写入器:每个ItemWriter获取10个要处理的记录.
我看过:
CompositeItemWriter:当我需要将项目均匀地分配给编写器时,似乎将所有读取的项目传递给所有编写器.
BackToBackPatternClassifier:我真的不需要分类器,因为我正在均匀地分割项目.
有没有另一种方法只有一个读者和多个作家?
或者我可以在我的Writer中手动创建线程?
spring-batch ×10
spring-boot ×6
java ×2
architecture ×1
batchsize ×1
jdbctemplate ×1
spring ×1
spring-cache ×1