BATCH-2189: Wrapped checked exception with a custom RuntimeException to follow rules for @PostConstruct

This commit is contained in:
Michael Minella
2014-03-18 13:06:21 -05:00
parent 4e5b4c12ba
commit 3a2cac3d49
2 changed files with 42 additions and 3 deletions

View File

@@ -0,0 +1,34 @@
/*
* Copyright 2014 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.batch.core.configuration;
/**
* Represents an error has occured in the configuration of base batch
* infrastructure (creation of a {@link org.springframework.batch.core.repository.JobRepository}
* for example.
*
* @author Michael Minella
* @since 2.2.6
*/
public class BatchConfigurationException extends RuntimeException {
/**
* @param t an exception to be wrapped
*/
public BatchConfigurationException(Throwable t) {
super(t);
}
}

View File

@@ -18,6 +18,7 @@ package org.springframework.batch.core.configuration.annotation;
import javax.annotation.PostConstruct;
import javax.sql.DataSource;
import org.springframework.batch.core.configuration.BatchConfigurationException;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.launch.support.SimpleJobLauncher;
import org.springframework.batch.core.repository.JobRepository;
@@ -63,9 +64,13 @@ public class DefaultBatchConfigurer implements BatchConfigurer {
}
@PostConstruct
public void initialize() throws Exception {
this.jobRepository = createJobRepository();
this.jobLauncher = createJobLauncher();
public void initialize() throws BatchConfigurationException {
try {
this.jobRepository = createJobRepository();
this.jobLauncher = createJobLauncher();
} catch (Exception e) {
throw new BatchConfigurationException(e);
}
}
private JobLauncher createJobLauncher() throws Exception {