X Tutup
Skip to content

Commit fece2c1

Browse files
committed
restored support for String-to-ContextResource conversion (SPR-8383)
1 parent 8b55b34 commit fece2c1

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

org.springframework.beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ else if (convertedValue instanceof String && !requiredType.isInstance(convertedV
223223
}
224224
if (editor != null) {
225225
msg.append(": PropertyEditor [").append(editor.getClass().getName()).append(
226-
"] returned inappropriate value");
226+
"] returned inappropriate value of type [").append(
227+
ClassUtils.getDescriptiveType(convertedValue)).append("]");
227228
throw new IllegalArgumentException(msg.toString());
228229
}
229230
else {

org.springframework.beans/src/main/java/org/springframework/beans/support/ResourceEditorRegistrar.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2010 the original author or authors.
2+
* Copyright 2002-2011 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,6 +34,7 @@
3434
import org.springframework.beans.propertyeditors.InputStreamEditor;
3535
import org.springframework.beans.propertyeditors.URIEditor;
3636
import org.springframework.beans.propertyeditors.URLEditor;
37+
import org.springframework.core.io.ContextResource;
3738
import org.springframework.core.io.Resource;
3839
import org.springframework.core.io.ResourceEditor;
3940
import org.springframework.core.io.ResourceLoader;
@@ -84,6 +85,7 @@ public ResourceEditorRegistrar(ResourceLoader resourceLoader) {
8485
public void registerCustomEditors(PropertyEditorRegistry registry) {
8586
ResourceEditor baseEditor = new ResourceEditor(this.resourceLoader);
8687
doRegisterEditor(registry, Resource.class, baseEditor);
88+
doRegisterEditor(registry, ContextResource.class, baseEditor);
8789
doRegisterEditor(registry, InputStream.class, new InputStreamEditor(baseEditor));
8890
doRegisterEditor(registry, InputSource.class, new InputSourceEditor(baseEditor));
8991
doRegisterEditor(registry, File.class, new FileEditor(baseEditor));

org.springframework.context/src/test/java/org/springframework/beans/ResourceTestBean.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2010 the original author or authors.
2+
* Copyright 2002-2011 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
1919
import java.io.InputStream;
2020
import java.util.Map;
2121

22+
import org.springframework.core.io.ContextResource;
2223
import org.springframework.core.io.Resource;
2324

2425
/**
@@ -29,6 +30,8 @@ public class ResourceTestBean {
2930

3031
private Resource resource;
3132

33+
private ContextResource contextResource;
34+
3235
private InputStream inputStream;
3336

3437
private Resource[] resourceArray;
@@ -47,22 +50,30 @@ public ResourceTestBean(Resource resource, InputStream inputStream) {
4750
}
4851

4952

53+
public Resource getResource() {
54+
return resource;
55+
}
56+
5057
public void setResource(Resource resource) {
5158
this.resource = resource;
5259
}
5360

54-
public void setInputStream(InputStream inputStream) {
55-
this.inputStream = inputStream;
61+
public ContextResource getContextResource() {
62+
return contextResource;
5663
}
5764

58-
public Resource getResource() {
59-
return resource;
65+
public void setContextResource(ContextResource contextResource) {
66+
this.contextResource = contextResource;
6067
}
6168

6269
public InputStream getInputStream() {
6370
return inputStream;
6471
}
6572

73+
public void setInputStream(InputStream inputStream) {
74+
this.inputStream = inputStream;
75+
}
76+
6677
public Resource[] getResourceArray() {
6778
return resourceArray;
6879
}

org.springframework.context/src/test/java/org/springframework/context/support/ClassPathXmlApplicationContextTests-resourceImport.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
<property name="resource">
88
<value>test.properties</value>
99
</property>
10+
<property name="contextResource">
11+
<value>testBeans.properties</value>
12+
</property>
1013
<property name="inputStream">
1114
<value>classpath:org/springframework/beans/factory/xml/test.properties</value>
1215
</property>

0 commit comments

Comments
 (0)
X Tutup