Skip to content

Commit 870507c

Browse files
committed
context-specific "conversionService" bean may refer to annotation-configured converter beans (SPR-6800)
1 parent 9adb01a commit 870507c

File tree

3 files changed

+55
-9
lines changed

3 files changed

+55
-9
lines changed

org.springframework.context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,12 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
191191
/** ResourcePatternResolver used by this context */
192192
private ResourcePatternResolver resourcePatternResolver;
193193

194-
/** MessageSource we delegate our implementation of this interface to */
195-
private MessageSource messageSource;
196-
197194
/** LifecycleProcessor for managing the lifecycle of beans within this context */
198195
private LifecycleProcessor lifecycleProcessor;
199196

197+
/** MessageSource we delegate our implementation of this interface to */
198+
private MessageSource messageSource;
199+
200200
/** Helper class used in event publishing */
201201
private ApplicationEventMulticaster applicationEventMulticaster;
202202

@@ -495,12 +495,6 @@ protected void prepareBeanFactory(ConfigurableListableBeanFactory beanFactory) {
495495
beanFactory.registerResolvableDependency(ApplicationEventPublisher.class, this);
496496
beanFactory.registerResolvableDependency(ApplicationContext.class, this);
497497

498-
// Initialize conversion service for this context.
499-
if (beanFactory.containsBean(CONVERSION_SERVICE_BEAN_NAME)) {
500-
beanFactory.setConversionService(
501-
beanFactory.getBean(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class));
502-
}
503-
504498
// Detect a LoadTimeWeaver and prepare for weaving, if found.
505499
if (beanFactory.containsBean(LOAD_TIME_WEAVER_BEAN_NAME)) {
506500
beanFactory.addBeanPostProcessor(new LoadTimeWeaverAwareProcessor(beanFactory));
@@ -861,6 +855,12 @@ protected void addListener(ApplicationListener listener) {
861855
* initializing all remaining singleton beans.
862856
*/
863857
protected void finishBeanFactoryInitialization(ConfigurableListableBeanFactory beanFactory) {
858+
// Initialize conversion service for this context.
859+
if (beanFactory.containsBean(CONVERSION_SERVICE_BEAN_NAME)) {
860+
beanFactory.setConversionService(
861+
beanFactory.getBean(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class));
862+
}
863+
864864
// Stop using the temporary ClassLoader for type matching.
865865
beanFactory.setTempClassLoader(null);
866866

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2002-2010 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.context.annotation;
18+
19+
import example.scannable.FooService;
20+
21+
import org.springframework.core.convert.converter.Converter;
22+
23+
/**
24+
* @author Juergen Hoeller
25+
*/
26+
public class FooServiceDependentConverter implements Converter<String, org.springframework.beans.TestBean> {
27+
28+
private FooService fooService;
29+
30+
public void setFooService(FooService fooService) {
31+
this.fooService = fooService;
32+
}
33+
34+
public org.springframework.beans.TestBean convert(String source) {
35+
return new org.springframework.beans.TestBean(source);
36+
}
37+
38+
}

org.springframework.context/src/test/java/org/springframework/context/annotation/simpleConfigTests.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,12 @@
2525

2626
<bean class="example.scannable.StubFooDao"/>
2727

28+
<bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
29+
<property name="converters">
30+
<bean class="org.springframework.context.annotation.FooServiceDependentConverter">
31+
<property name="fooService" ref="fooServiceImpl"/>
32+
</bean>
33+
</property>
34+
</bean>
35+
2836
</beans>

0 commit comments

Comments
 (0)