├── .gitignore
├── src
├── main
│ ├── resources
│ │ ├── business-schema-hsqldb.sql
│ │ ├── application.properties
│ │ ├── batch-hsql.properties
│ │ └── META-INF
│ │ │ └── spring
│ │ │ └── batch
│ │ │ └── override
│ │ │ └── servlet
│ │ │ └── manager
│ │ │ └── integration-context.xml
│ └── java
│ │ └── de
│ │ └── codecentric
│ │ └── batch
│ │ ├── config
│ │ ├── MainConfiguration.java
│ │ ├── WebappConfiguration.java
│ │ └── ServletConfiguration.java
│ │ └── SpringBatchAdmin.java
└── test
│ └── java
│ └── de
│ └── codecentric
│ └── batch
│ ├── BatchTest.java
│ └── TestBatchConfiguration.java
├── HsqldbServer.launch
├── README.md
├── pom.xml
└── LICENSE.TXT
/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | /.settings/
3 | /.classpath
4 | /.project
5 | /.springBeans
6 |
--------------------------------------------------------------------------------
/src/main/resources/business-schema-hsqldb.sql:
--------------------------------------------------------------------------------
1 | select 1 from information_schema.system_users;
--------------------------------------------------------------------------------
/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | server.servletPath=/*
2 | spring.freemarker.checkTemplateLocation=false
3 | ENVIRONMENT=hsql
--------------------------------------------------------------------------------
/HsqldbServer.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/main/resources/batch-hsql.properties:
--------------------------------------------------------------------------------
1 | # Placeholders batch.*
2 | # for HSQLDB:
3 | batch.jdbc.driver=org.hsqldb.jdbcDriver
4 | #batch.jdbc.url=jdbc:hsqldb:mem:testdb;sql.enforce_strict_size=true;hsqldb.tx=mvcc
5 | # Override and use this one in for a separate server process so you can inspect
6 | # the results (or add it to system properties with -D to override at run time).
7 | batch.jdbc.url=jdbc:hsqldb:hsql://localhost
8 | batch.jdbc.user=sa
9 | batch.jdbc.password=
10 | batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer
11 | batch.schema.script=classpath*:/org/springframework/batch/core/schema-hsqldb.sql
12 | batch.drop.script=classpath*:/org/springframework/batch/core/schema-drop-hsqldb.sql
13 | batch.jdbc.testWhileIdle=true
14 | batch.jdbc.validationQuery=
15 |
16 |
17 | # Non-platform dependent settings that you might like to change
18 | batch.data.source.init=true
19 | batch.table.prefix=BATCH_
20 |
21 | batch.business.schema.script=classpath:/business-schema-hsqldb.sql
22 |
--------------------------------------------------------------------------------
/src/main/resources/META-INF/spring/batch/override/servlet/manager/integration-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/main/java/de/codecentric/batch/config/MainConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package de.codecentric.batch.config;
17 |
18 | import org.springframework.context.annotation.Configuration;
19 | import org.springframework.context.annotation.Import;
20 |
21 | /**
22 | * This is the main configuration class for the application.
23 | *
24 | * @author Thomas Bosch
25 | */
26 | @Configuration
27 | @Import({ ServletConfiguration.class, WebappConfiguration.class })
28 | public class MainConfiguration {
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/de/codecentric/batch/config/WebappConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package de.codecentric.batch.config;
17 |
18 | import org.springframework.context.annotation.Configuration;
19 | import org.springframework.context.annotation.ImportResource;
20 |
21 | /**
22 | * Just the import of the webapp-config.xml of spring-batch-admin-manager.
23 | *
24 | * @author Thomas Bosch
25 | */
26 | @Configuration
27 | @ImportResource("classpath:/org/springframework/batch/admin/web/resources/webapp-config.xml")
28 | public class WebappConfiguration {
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/de/codecentric/batch/config/ServletConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package de.codecentric.batch.config;
17 |
18 | import org.springframework.context.annotation.Configuration;
19 | import org.springframework.context.annotation.ImportResource;
20 |
21 | /**
22 | * Just the import of the servlet-config.xml of spring-batch-admin-manager.
23 | *
24 | * @author Thomas Bosch
25 | */
26 | @Configuration
27 | @ImportResource("classpath:/org/springframework/batch/admin/web/resources/servlet-config.xml")
28 | public class ServletConfiguration {
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | spring-batch-admin-spring-boot
2 | ================================
3 |
4 | This is a a Spring Boot capsule of the standard [Spring Batch Admin](https://github.com/spring-projects/spring-batch-admin "Github") application of the [Spring Batch](http://projects.spring.io/spring-batch/ "SpringIO Page") team.
5 |
6 | With this capsule it is possible to run the **Spring Batch Admin** as a **Spring Boot** application instead of deploying it to a servlet container like tomcat.
7 |
8 | As default configuration a local HSQLDB database is used for the batch metadata.
9 |
10 | This can be changed:
11 |
12 | 1. You have other HSQLDB properties?
13 | * Just change the entries inside batch-hsql.properties
14 | 2. You prefer to use another database system?
15 | * Delete the file batch-hsql.properties
16 | * Add a new file batch-[*your-db*].properties (a template can be found in the root of spring-batch-core.jar)
17 | * Set the property *ENVIRONMENT* in application.properties to *your-db* (means i.e. batch-oracle.properties with ENVIRONMENT=oracle)
18 |
19 | You can test the running application by starting the JUnit test class *BatchTest* that can be found in the test sources folder.
20 |
21 | Feel free to use it. The current version of **Spring Batch Admin** can be modified in the pom.xml.
--------------------------------------------------------------------------------
/src/test/java/de/codecentric/batch/BatchTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package de.codecentric.batch;
17 |
18 | import org.junit.Test;
19 | import org.junit.runner.RunWith;
20 | import org.springframework.batch.core.Job;
21 | import org.springframework.batch.core.JobParameters;
22 | import org.springframework.batch.core.launch.JobLauncher;
23 | import org.springframework.beans.factory.annotation.Autowired;
24 | import org.springframework.test.context.ContextConfiguration;
25 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
26 |
27 | /**
28 | * This is a test class to run a batch. It is needed to have a running HSQLDB server to store the metadata. Details of
29 | * the run can be viewed in the spring-batch-admin view, i.e. at http://localhost:8080
30 | *
31 | * @author Thomas Bosch
32 | */
33 | @ContextConfiguration(classes = { TestBatchConfiguration.class })
34 | @RunWith(SpringJUnit4ClassRunner.class)
35 | public class BatchTest {
36 |
37 | @Autowired
38 | private JobLauncher jobLauncher;
39 |
40 | @Autowired
41 | private Job job;
42 |
43 | @Test
44 | public void startBatch() throws Exception {
45 | jobLauncher.run(job, new JobParameters());
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/de/codecentric/batch/SpringBatchAdmin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package de.codecentric.batch;
17 |
18 | import org.springframework.boot.SpringApplication;
19 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
20 | import org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration;
21 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
22 | import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
23 | import org.springframework.boot.builder.SpringApplicationBuilder;
24 | import org.springframework.boot.context.web.SpringBootServletInitializer;
25 | import org.springframework.context.annotation.Configuration;
26 | import org.springframework.context.annotation.Import;
27 |
28 | import de.codecentric.batch.config.MainConfiguration;
29 |
30 | /**
31 | * Main class to start the Spring Boot application. There are two ways to start it. First: Just run the main method of
32 | * this class. Second: Create a war file with the spring-boot-maven-plugin and deploy it to tomcat or another servlet
33 | * container.
34 | *
35 | * @author Thomas Bosch
36 | */
37 | @Configuration
38 | @EnableAutoConfiguration(exclude = { BatchAutoConfiguration.class, DataSourceAutoConfiguration.class,
39 | WebMvcAutoConfiguration.class })
40 | @Import(MainConfiguration.class)
41 | public class SpringBatchAdmin extends SpringBootServletInitializer {
42 |
43 | /**
44 | * Run application.
45 | *
46 | * @param args
47 | * Parameters to pass to SpringApplication.
48 | */
49 | public static void main(String[] args) {
50 | SpringApplication.run(SpringBatchAdmin.class, args);
51 | }
52 |
53 | /**
54 | * @see org.springframework.boot.context.web.SpringBootServletInitializer#configure(org.springframework.boot.builder.SpringApplicationBuilder)
55 | */
56 | @Override
57 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
58 | return application.sources(SpringBatchAdmin.class);
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/src/test/java/de/codecentric/batch/TestBatchConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package de.codecentric.batch;
17 |
18 | import java.util.Arrays;
19 | import java.util.List;
20 |
21 | import javax.sql.DataSource;
22 |
23 | import org.apache.commons.dbcp.BasicDataSource;
24 | import org.hsqldb.jdbcDriver;
25 | import org.springframework.batch.core.Job;
26 | import org.springframework.batch.core.Step;
27 | import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
28 | import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
29 | import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
30 | import org.springframework.batch.item.ItemReader;
31 | import org.springframework.batch.item.ItemWriter;
32 | import org.springframework.batch.item.support.ListItemReader;
33 | import org.springframework.beans.factory.annotation.Autowired;
34 | import org.springframework.context.annotation.Bean;
35 | import org.springframework.context.annotation.Configuration;
36 |
37 | @Configuration
38 | @EnableBatchProcessing(modular = true)
39 | public class TestBatchConfiguration {
40 |
41 | @Autowired
42 | private JobBuilderFactory jobBuilderFactory;
43 |
44 | @Autowired
45 | private StepBuilderFactory stepBuilderFactory;
46 |
47 | @Bean
48 | public Job job() {
49 | return jobBuilderFactory.get("job").start(step()).build();
50 | }
51 |
52 | @Bean
53 | public Step step() {
54 | return stepBuilderFactory.get("step").chunk(1).reader(reader()).writer(writer()).build();
55 | }
56 |
57 | @Bean
58 | public ItemReader reader() {
59 | return new ListItemReader(Arrays.asList("1", "2", "3"));
60 | }
61 |
62 | @Bean
63 | public ItemWriter super Object> writer() {
64 | return new ItemWriter