diff --git a/complete/pom.xml b/complete/pom.xml
index 353717c260..b1f81ee766 100644
--- a/complete/pom.xml
+++ b/complete/pom.xml
@@ -16,39 +16,16 @@
org.springframework.bootstrap
- spring-bootstrap-starter
- 0.5.0.BUILD-SNAPSHOT
-
-
- org.springframework.batch
- spring-batch-core
- 2.2.0.BUILD-SNAPSHOT
-
-
- org.springframework
- spring-jdbc
- ${spring.framework.version}
-
-
- org.springframework
- spring-tx
- ${spring.framework.version}
-
-
- commons-dbcp
- commons-dbcp
- 1.2.2
+ spring-bootstrap-batch-starter
org.hsqldb
hsqldb
- 2.2.9
- hello.Application
- 4.0.0.BUILD-SNAPSHOT
+ hello.BatchConfiguration
diff --git a/complete/src/main/java/hello/Application.java b/complete/src/main/java/hello/Application.java
deleted file mode 100644
index 262db7ac99..0000000000
--- a/complete/src/main/java/hello/Application.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package hello;
-
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.List;
-
-import org.springframework.batch.core.Job;
-import org.springframework.batch.core.JobParametersBuilder;
-import org.springframework.batch.core.launch.JobLauncher;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.annotation.AnnotationConfigApplicationContext;
-import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.jdbc.core.RowMapper;
-
-public class Application {
-
- public static void main(String[] args) throws Exception {
- ApplicationContext ctx = new AnnotationConfigApplicationContext(BatchConfiguration.class);
- JobLauncher jobLauncher = ctx.getBean(JobLauncher.class);
- jobLauncher.run(ctx.getBean(Job.class), new JobParametersBuilder().toJobParameters());
-
- JdbcTemplate jdbcTemplate = ctx.getBean(JdbcTemplate.class);
- List results = jdbcTemplate.query("select first_name, last_name from PEOPLE", new RowMapper() {
- @Override
- public Person mapRow(final ResultSet rs, int rowNum) throws SQLException {
- return new Person() {{
- setFirstName(rs.getString(1));
- setLastName(rs.getString(2));
- }};
- }
- });
- for (Person person : results) {
- System.out.println("Found <" + person + "> in the database.");
- }
- }
-
-}
diff --git a/complete/src/main/java/hello/BatchConfiguration.java b/complete/src/main/java/hello/BatchConfiguration.java
index 0d42436c02..c573113d03 100644
--- a/complete/src/main/java/hello/BatchConfiguration.java
+++ b/complete/src/main/java/hello/BatchConfiguration.java
@@ -17,45 +17,48 @@ import org.springframework.batch.item.file.FlatFileItemReader;
import org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper;
import org.springframework.batch.item.file.mapping.DefaultLineMapper;
import org.springframework.batch.item.file.transform.DelimitedLineTokenizer;
+import org.springframework.bootstrap.SpringApplication;
+import org.springframework.bootstrap.context.annotation.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
@Configuration
@EnableBatchProcessing
+@EnableAutoConfiguration
public class BatchConfiguration {
- @Bean
- public DataSource dataSource() {
- return new EmbeddedDatabaseBuilder().
- addScript("classpath:org/springframework/batch/core/schema-drop-hsqldb.sql").
- addScript("classpath:org/springframework/batch/core/schema-hsqldb.sql").
- addScript("classpath:person.sql").
- build();
+ public static void main(String[] args) {
+ SpringApplication.run(BatchConfiguration.class, args);
}
-
+
@Bean
public JdbcTemplate jdbcTemplate(DataSource dataSource) {
return new JdbcTemplate(dataSource);
}
-
+
@Bean
public ItemReader reader() {
FlatFileItemReader reader = new FlatFileItemReader();
reader.setResource(new ClassPathResource("sample-data.csv"));
- reader.setLineMapper(new DefaultLineMapper() {{
- setLineTokenizer(new DelimitedLineTokenizer(){{
- setNames(new String[]{"firstName", "lastName"});
- }});
- setFieldSetMapper(new BeanWrapperFieldSetMapper(){{
- setTargetType(Person.class);
- }});
- }});
+ reader.setLineMapper(new DefaultLineMapper() {
+ {
+ setLineTokenizer(new DelimitedLineTokenizer() {
+ {
+ setNames(new String[] { "firstName", "lastName" });
+ }
+ });
+ setFieldSetMapper(new BeanWrapperFieldSetMapper() {
+ {
+ setTargetType(Person.class);
+ }
+ });
+ }
+ });
return reader;
}
-
+
@Bean
public ItemProcessor processor() {
return new PersonItemProcessor();
@@ -69,26 +72,19 @@ public class BatchConfiguration {
writer.setDataSource(dataSource);
return writer;
}
-
+
@Bean
public Job importUserJob(JobBuilderFactory jobs, Step s1) {
- Job job = jobs.get("importUserJob")
- .incrementer(new RunIdIncrementer())
- .flow(s1)
- .end()
- .build();
+ Job job = jobs.get("importUserJob").incrementer(new RunIdIncrementer()).flow(s1)
+ .end().build();
return job;
}
-
+
@Bean
- public Step step1(StepBuilderFactory stepBuilderFactory, ItemReader reader,
+ public Step step1(StepBuilderFactory stepBuilderFactory, ItemReader reader,
ItemWriter writer, ItemProcessor processor) {
- return stepBuilderFactory.get("step1")
- . chunk(10)
- .reader(reader)
- .processor(processor)
- .writer(writer)
- .build();
+ return stepBuilderFactory.get("step1"). chunk(10).reader(reader)
+ .processor(processor).writer(writer).build();
}
-
+
}
diff --git a/complete/src/main/resources/log4j.properties b/complete/src/main/resources/log4j.properties
deleted file mode 100644
index 49817983a1..0000000000
--- a/complete/src/main/resources/log4j.properties
+++ /dev/null
@@ -1,9 +0,0 @@
-log4j.rootCategory=TRACE, stdout
-
-log4j.appender.stdout=org.apache.log4j.ConsoleAppender
-log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
-log4j.appender.stdout.layout.ConversionPattern=%d %p %t [%c] - <%m>%n
-
-#log4j.org.springframework.batch=DEBUG
-#log4j.org.springframework.integration=DEBUG
-#log4j.org.hsqldb=DEBUG
\ No newline at end of file
diff --git a/complete/src/main/resources/logging.properties b/complete/src/main/resources/logging.properties
index 60a0286380..a92360687d 100644
--- a/complete/src/main/resources/logging.properties
+++ b/complete/src/main/resources/logging.properties
@@ -1,6 +1,5 @@
handlers = java.util.logging.ConsoleHandler
.level = ALL
-.formatter = java.util.logging.SimpleFormatter
org.springframework.batch.level = FINE
org.springframework.integration.level = FINE
org.hsqldb.level = FINE
\ No newline at end of file
diff --git a/complete/src/main/resources/person.sql b/complete/src/main/resources/schema.sql
similarity index 100%
rename from complete/src/main/resources/person.sql
rename to complete/src/main/resources/schema.sql