Repository: camel Updated Branches: refs/heads/master aa3c22b61 -> d53e4000a
[Spring Boot] Improved conditional creation of ConversionService. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d53e4000 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d53e4000 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d53e4000 Branch: refs/heads/master Commit: d53e4000a1199b15627dbe212bfd84fa9b3ddd84 Parents: aa3c22b Author: Henryk Konsek <[email protected]> Authored: Fri Jan 2 16:33:24 2015 +0100 Committer: Henryk Konsek <[email protected]> Committed: Fri Jan 2 16:33:24 2015 +0100 ---------------------------------------------------------------------- .../SpringConversionServiceConfiguration.java | 2 +- .../boot/ExistingConversionServiceTest.java | 61 ++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/d53e4000/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringConversionServiceConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringConversionServiceConfiguration.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringConversionServiceConfiguration.java index eb0dab0..5ca2373 100644 --- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringConversionServiceConfiguration.java +++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringConversionServiceConfiguration.java @@ -27,7 +27,7 @@ import org.springframework.core.convert.support.DefaultConversionService; @Configuration public class SpringConversionServiceConfiguration { - @ConditionalOnMissingBean + @ConditionalOnMissingBean(ConversionService.class) @Bean ConversionService conversionService(ApplicationContext applicationContext) { DefaultConversionService service = new DefaultConversionService(); http://git-wip-us.apache.org/repos/asf/camel/blob/d53e4000/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/ExistingConversionServiceTest.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/ExistingConversionServiceTest.java b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/ExistingConversionServiceTest.java new file mode 100644 index 0000000..e0910fe --- /dev/null +++ b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/ExistingConversionServiceTest.java @@ -0,0 +1,61 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.camel.spring.boot; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.IntegrationTest; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.convert.ConversionService; +import org.springframework.core.convert.support.DefaultConversionService; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import static org.apache.camel.spring.boot.ConversionServiceConfig.providedConversionService; + +@RunWith(SpringJUnit4ClassRunner.class) +@EnableAutoConfiguration +@SpringApplicationConfiguration(classes = ConversionServiceConfig.class) +@IntegrationTest +public class ExistingConversionServiceTest extends Assert { + + @Autowired + ConversionService conversionService; + + @Test + public void shouldUseProvidedConversionService() { + assertSame(providedConversionService, conversionService); + } + +} + +@Configuration +class ConversionServiceConfig { + + static ConversionService providedConversionService = new DefaultConversionService(); + + @Bean + ConversionService conversionService() { + return providedConversionService; + } + +} +
