diff --git a/pom.xml b/pom.xml index b2bb687a969..1ffb2412821 100644 --- a/pom.xml +++ b/pom.xml @@ -22,6 +22,8 @@ UTF-8 4.0.0.BOOTSTRAP-SNAPSHOT 1.0.0.CI-SNAPSHOT + 2.2.3.RELEASE + 2.2.0.RC1 ${project.basedir} @@ -33,6 +35,14 @@ true + + spring-milestones + Spring Milestones + http://maven.springframework.org/milestone + + false + + @@ -356,6 +366,16 @@ spring-tx ${dependency.springframework.version} + + org.springframework.batch + spring-batch-core + ${dependency.spring.batch.version} + + + org.springframework.integration + spring-integration-core + ${dependency.spring.integration.version} + org.springframework.data spring-data-jpa diff --git a/spring-bootstrap-cli/samples/job.groovy b/spring-bootstrap-cli/samples/job.groovy index c2497ffdabb..4daddca98d1 100644 --- a/spring-bootstrap-cli/samples/job.groovy +++ b/spring-bootstrap-cli/samples/job.groovy @@ -32,55 +32,4 @@ class JobConfig { } } -import groovy.util.logging.Log -import org.springframework.util.StringUtils -import groovy.util.logging.Log - -@Component -@Log -class JobRunner implements CommandLineRunner { - - @Autowired(required=false) - private JobParametersConverter converter = new DefaultJobParametersConverter() - - @Autowired - private JobLauncher jobLauncher - - @Autowired - private Job job - - void run(String... args) { - log.info("Running default command line with: ${args}") - launchJobFromProperties(StringUtils.splitArrayElementsIntoProperties(args, "=")) - } - - protected void launchJobFromProperties(Properties properties) { - jobLauncher.run(job, converter.getJobParameters(properties)) - } -} - -import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils -import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator - -@Component -class DatabaseInitializer { - - @Autowired - private DataSource dataSource - - @Autowired - private ResourceLoader resourceLoader - - @PostConstruct - protected void initialize() { - String platform = org.springframework.batch.support.DatabaseType.fromMetaData(dataSource).toString().toLowerCase() - if (platform=="hsql") { - platform = "hsqldb" - } - ResourceDatabasePopulator populator = new ResourceDatabasePopulator() - populator.addScript(resourceLoader.getResource("org/springframework/batch/core/schema-${platform}.sql")) - populator.setContinueOnError(true) - DatabasePopulatorUtils.execute(populator, dataSource) - } -} diff --git a/spring-bootstrap-samples/spring-bootstrap-integration-sample/pom.xml b/spring-bootstrap-samples/spring-bootstrap-integration-sample/pom.xml index a6d8a37b751..98adc7973fc 100644 --- a/spring-bootstrap-samples/spring-bootstrap-integration-sample/pom.xml +++ b/spring-bootstrap-samples/spring-bootstrap-integration-sample/pom.xml @@ -12,7 +12,6 @@ ${project.basedir}/../.. org.springframework.bootstrap.sample.service.IntegrationBootstrapApplication - 2.2.3.RELEASE @@ -23,12 +22,11 @@ org.springframework.integration spring-integration-core - ${spring.integration.version} org.springframework.integration spring-integration-stream - ${spring.integration.version} + ${dependency.spring.integration.version} ch.qos.logback diff --git a/spring-bootstrap/pom.xml b/spring-bootstrap/pom.xml index 7bd43d7e57a..241684f7a1f 100644 --- a/spring-bootstrap/pom.xml +++ b/spring-bootstrap/pom.xml @@ -97,6 +97,16 @@ spring-data-jpa true + + org.springframework.batch + spring-batch-core + true + + + org.springframework.integration + spring-integration-core + true + ch.qos.logback logback-classic diff --git a/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/batch/BatchAutoConfiguration.java b/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/batch/BatchAutoConfiguration.java new file mode 100644 index 00000000000..f5634d5bde8 --- /dev/null +++ b/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/batch/BatchAutoConfiguration.java @@ -0,0 +1,48 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.bootstrap.autoconfigure.batch; + +import org.springframework.batch.core.launch.JobLauncher; +import org.springframework.bootstrap.CommandLineRunner; +import org.springframework.bootstrap.context.annotation.ConditionalOnClass; +import org.springframework.bootstrap.context.annotation.ConditionalOnMissingBean; +import org.springframework.bootstrap.context.annotation.EnableAutoConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * {@link EnableAutoConfiguration Auto-configuration} for Spring Batch. + * + * @author Dave Syer + */ +@Configuration +@ConditionalOnClass({ JobLauncher.class }) +public class BatchAutoConfiguration { + + @Bean + // Harmless to always include this, but maybe could make it conditional as well + public BatchDatabaseInitializer batchDatabaseInitializer() { + return new BatchDatabaseInitializer(); + } + + @Bean + @ConditionalOnMissingBean({ CommandLineRunner.class }) + public JobLauncherCommandLineRunner jobLauncherCommandLineRunner() { + return new JobLauncherCommandLineRunner(); + } + +} diff --git a/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/batch/BatchDatabaseInitializer.java b/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/batch/BatchDatabaseInitializer.java new file mode 100644 index 00000000000..a11f3202e4a --- /dev/null +++ b/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/batch/BatchDatabaseInitializer.java @@ -0,0 +1,53 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.bootstrap.autoconfigure.batch; + +import javax.annotation.PostConstruct; +import javax.sql.DataSource; + +import org.springframework.batch.support.DatabaseType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.ResourceLoader; +import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils; +import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; +import org.springframework.stereotype.Component; + +@Component +public class BatchDatabaseInitializer { + + @Autowired + private DataSource dataSource; + + @Autowired + private ResourceLoader resourceLoader; + + @PostConstruct + protected void initialize() throws Exception { + String platform = DatabaseType.fromMetaData(this.dataSource).toString() + .toLowerCase(); + if ("hsql".equals(platform)) { + platform = "hsqldb"; + } + ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); + populator + .addScript(this.resourceLoader + .getResource("org/springframework/batch/core/schema-" + platform + + ".sql")); + populator.setContinueOnError(true); + DatabasePopulatorUtils.execute(populator, this.dataSource); + } + +} \ No newline at end of file diff --git a/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/batch/JobLauncherCommandLineRunner.java b/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/batch/JobLauncherCommandLineRunner.java new file mode 100644 index 00000000000..e0262907d98 --- /dev/null +++ b/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/batch/JobLauncherCommandLineRunner.java @@ -0,0 +1,62 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.bootstrap.autoconfigure.batch; + +import java.util.Arrays; +import java.util.Properties; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.batch.core.Job; +import org.springframework.batch.core.JobExecutionException; +import org.springframework.batch.core.converter.DefaultJobParametersConverter; +import org.springframework.batch.core.converter.JobParametersConverter; +import org.springframework.batch.core.launch.JobLauncher; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.bootstrap.CommandLineRunner; +import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; + +@Component +// FIXME: what to do with more than one Job? +public class JobLauncherCommandLineRunner implements CommandLineRunner { + + private static Log logger = LogFactory.getLog(JobLauncherCommandLineRunner.class); + + @Autowired(required = false) + private JobParametersConverter converter = new DefaultJobParametersConverter(); + + @Autowired + private JobLauncher jobLauncher; + + @Autowired + private Job job; + + public void run(String... args) { + logger.info("Running default command line with: " + Arrays.asList(args)); + launchJobFromProperties(StringUtils.splitArrayElementsIntoProperties(args, + "=")); + } + + protected void launchJobFromProperties(Properties properties) { + try { + this.jobLauncher.run(this.job, + this.converter.getJobParameters(properties)); + } catch (JobExecutionException e) { + throw new IllegalStateException("Could not run job", e); + } + } +} \ No newline at end of file diff --git a/spring-bootstrap/src/main/resources/META-INF/spring.factories b/spring-bootstrap/src/main/resources/META-INF/spring.factories index a294a9efb74..cbadd2cc47a 100644 --- a/spring-bootstrap/src/main/resources/META-INF/spring.factories +++ b/spring-bootstrap/src/main/resources/META-INF/spring.factories @@ -2,6 +2,7 @@ org.springframework.bootstrap.context.annotation.EnableAutoConfiguration=\ org.springframework.bootstrap.autoconfigure.PropertyPlaceholderAutoConfiguration,\ org.springframework.bootstrap.autoconfigure.data.JpaRepositoriesAutoConfiguration,\ org.springframework.bootstrap.autoconfigure.jdbc.EmbeddedDatabaseAutoConfiguration,\ +org.springframework.bootstrap.autoconfigure.batch.BatchAutoConfiguration,\ org.springframework.bootstrap.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,\ org.springframework.bootstrap.autoconfigure.web.EmbeddedJettyAutoConfiguration,\ org.springframework.bootstrap.autoconfigure.web.EmbeddedTomcatAutoConfiguration,\