Closed
Description
Olav Reinert opened SPR-7083 and commented
If I create a bean with a property of type java.net.URI
, and try to initialize it in an XML bean definition file, I'm unable to define a URI instance with a fragment in it.
For example, consider the following bean definition
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="bean" class="TestInitURI">
<property name="uriSpec" value="env://server#3" />
<property name="uri" value="env://server#3" />
</bean>
</beans>
I apply this bean definition using the following test program:
import java.net.URI;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
public class TestInitURI {
private String uriSpec;
private URI uri;
public void setUri(URI uri) { this.uri = uri; }
public void setUriSpec(String uriSpec) { this.uriSpec = uriSpec; }
public static void main(String[] args) {
BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("beans.xml"));
TestInitURI bean = beanFactory.getBean(TestInitURI.class);
show("Bean property", bean.uri);
show("Expected ", URI.create(bean.uriSpec));
}
private static void show(String prefix, URI uri) {
System.out.println(prefix + " URI " + uri + " (host=" + uri.getHost() + ", authority=" + uri.getAuthority() + ", path="
+ uri.getPath() + ", fragment=" + uri.getFragment() + ")");
}
}
The output is the following:
Bean property URI env://server%233 (host=null, authority=server#3, path=, fragment=null)
Expected URI env://server#3 (host=server, authority=server, path=, fragment=3)
In other words, I would expect that defining a URI property in an XML bean definition file with a string constant is equivalent to initializing that property with a URI created by invoking URI.create(String)
with the same string constant.
Affects: 3.0.2
Issue Links:
- URIEditor should not double escape classpath: URIs [SPR-16581] #21123 URIEditor should not double escape classpath: URIs
Referenced from: commits 03120b7