SpEL performs String->String type conversion even within concatenated String
Issue: SPR-11215
This commit is contained in:
@@ -23,10 +23,8 @@ import java.util.Properties;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
import org.springframework.beans.factory.ObjectFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
@@ -38,13 +36,18 @@ import org.springframework.beans.factory.support.AutowireCandidateQualifier;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.support.GenericBeanDefinition;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.tests.Assume;
|
||||
import org.springframework.tests.TestGroup;
|
||||
import org.springframework.context.annotation.AnnotationConfigUtils;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.convert.support.GenericConversionService;
|
||||
import org.springframework.tests.Assume;
|
||||
import org.springframework.tests.TestGroup;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
import org.springframework.util.SerializationTestUtils;
|
||||
import org.springframework.util.StopWatch;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.0
|
||||
@@ -190,27 +193,35 @@ public class ApplicationContextExpressionTests {
|
||||
public void prototypeCreationReevaluatesExpressions() {
|
||||
GenericApplicationContext ac = new GenericApplicationContext();
|
||||
AnnotationConfigUtils.registerAnnotationConfigProcessors(ac);
|
||||
GenericConversionService cs = new GenericConversionService();
|
||||
cs.addConverter(String.class, String.class, new Converter<String, String>() {
|
||||
@Override
|
||||
public String convert(String source) {
|
||||
return source.trim();
|
||||
}
|
||||
});
|
||||
ac.getBeanFactory().registerSingleton(GenericApplicationContext.CONVERSION_SERVICE_BEAN_NAME, cs);
|
||||
RootBeanDefinition rbd = new RootBeanDefinition(PrototypeTestBean.class);
|
||||
rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
|
||||
rbd.getPropertyValues().add("country", "#{systemProperties.country}");
|
||||
rbd.getPropertyValues().add("country2", new TypedStringValue("#{systemProperties.country}"));
|
||||
rbd.getPropertyValues().add("country2", new TypedStringValue("-#{systemProperties.country}-"));
|
||||
ac.registerBeanDefinition("test", rbd);
|
||||
ac.refresh();
|
||||
|
||||
try {
|
||||
System.getProperties().put("name", "juergen1");
|
||||
System.getProperties().put("country", "UK1");
|
||||
System.getProperties().put("country", " UK1 ");
|
||||
PrototypeTestBean tb = (PrototypeTestBean) ac.getBean("test");
|
||||
assertEquals("juergen1", tb.getName());
|
||||
assertEquals("UK1", tb.getCountry());
|
||||
assertEquals("UK1", tb.getCountry2());
|
||||
assertEquals("-UK1-", tb.getCountry2());
|
||||
|
||||
System.getProperties().put("name", "juergen2");
|
||||
System.getProperties().put("country", "UK2");
|
||||
System.getProperties().put("country", " UK2 ");
|
||||
tb = (PrototypeTestBean) ac.getBean("test");
|
||||
assertEquals("juergen2", tb.getName());
|
||||
assertEquals("UK2", tb.getCountry());
|
||||
assertEquals("UK2", tb.getCountry2());
|
||||
assertEquals("-UK2-", tb.getCountry2());
|
||||
}
|
||||
finally {
|
||||
System.getProperties().remove("name");
|
||||
|
||||
Reference in New Issue
Block a user