diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/JobRepositoryParser.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/JobRepositoryParser.java index bfcca5644..91a6935bd 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/JobRepositoryParser.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/JobRepositoryParser.java @@ -15,8 +15,10 @@ */ package org.springframework.batch.core.configuration.xml; +import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.RuntimeBeanReference; +import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; @@ -38,46 +40,60 @@ public class JobRepositoryParser extends AbstractSingleBeanDefinitionParser { return "org.springframework.batch.core.repository.support.JobRepositoryFactoryBean"; } + @Override + protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext) + throws BeanDefinitionStoreException { + + String id = element.getAttribute(ID_ATTRIBUTE); + if (!StringUtils.hasText(id)) { + id = "jobRepository"; + } + + return id; + + } + /** * Parse and create a bean definition for a * {@link org.springframework.batch.core.repository.support.JobRepositoryFactoryBean} * . */ @Override - protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { + protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { CoreNamespaceUtils.autoregisterBeansForNamespace(parserContext, element); - String dataSource = element.getAttribute("data-source"); + String dataSource = element.getAttribute("data-source"); - String transactionManager = element.getAttribute("transaction-manager"); + String transactionManager = element.getAttribute("transaction-manager"); - String isolationLevelForCreate = element.getAttribute("isolation-level-for-create"); - - String tablePrefix = element.getAttribute("table-prefix"); - - String maxVarCharLength = element.getAttribute("max-varchar-length"); - - String lobHandler = element.getAttribute("lob-handler"); - - RuntimeBeanReference ds = new RuntimeBeanReference(dataSource); - builder.addPropertyValue("dataSource", ds); - RuntimeBeanReference tx = new RuntimeBeanReference(transactionManager); - builder.addPropertyValue("transactionManager", tx); - if (StringUtils.hasText(isolationLevelForCreate)) { - builder.addPropertyValue("isolationLevelForCreate", DefaultTransactionDefinition.PREFIX_ISOLATION+isolationLevelForCreate); - } - if (StringUtils.hasText(tablePrefix)) { - builder.addPropertyValue("tablePrefix", tablePrefix); - } - if (StringUtils.hasText(lobHandler)) { - builder.addPropertyReference("lobHandler", lobHandler); - } - if (StringUtils.hasText(maxVarCharLength)) { - builder.addPropertyValue("maxVarCharLength", maxVarCharLength); - } + String isolationLevelForCreate = element.getAttribute("isolation-level-for-create"); - builder.setRole(BeanDefinition.ROLE_SUPPORT); + String tablePrefix = element.getAttribute("table-prefix"); - } + String maxVarCharLength = element.getAttribute("max-varchar-length"); + + String lobHandler = element.getAttribute("lob-handler"); + + RuntimeBeanReference ds = new RuntimeBeanReference(dataSource); + builder.addPropertyValue("dataSource", ds); + RuntimeBeanReference tx = new RuntimeBeanReference(transactionManager); + builder.addPropertyValue("transactionManager", tx); + if (StringUtils.hasText(isolationLevelForCreate)) { + builder.addPropertyValue("isolationLevelForCreate", DefaultTransactionDefinition.PREFIX_ISOLATION + + isolationLevelForCreate); + } + if (StringUtils.hasText(tablePrefix)) { + builder.addPropertyValue("tablePrefix", tablePrefix); + } + if (StringUtils.hasText(lobHandler)) { + builder.addPropertyReference("lobHandler", lobHandler); + } + if (StringUtils.hasText(maxVarCharLength)) { + builder.addPropertyValue("maxVarCharLength", maxVarCharLength); + } + + builder.setRole(BeanDefinition.ROLE_SUPPORT); + + } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobRepositoryDefaultParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobRepositoryDefaultParserTests.java new file mode 100644 index 000000000..79ef3ecfe --- /dev/null +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobRepositoryDefaultParserTests.java @@ -0,0 +1,46 @@ +/* + * Copyright 2006-2007 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.xml; + +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.batch.core.repository.JobRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + + +/** + * @author Dave Syer + * + */ +@ContextConfiguration +@RunWith(SpringJUnit4ClassRunner.class) +public class JobRepositoryDefaultParserTests { + + @Autowired + @Qualifier("jobRepository") + private JobRepository jobRepository; + + @Test + public void testOneStep() throws Exception { + assertNotNull(jobRepository); + } + +} diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/JobRepositoryDefaultParserTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/JobRepositoryDefaultParserTests-context.xml new file mode 100644 index 000000000..03408114b --- /dev/null +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/JobRepositoryDefaultParserTests-context.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + \ No newline at end of file