Disable Spring URL resource loading in context file

I need to specify a url in a Spring context file, but don't want Spring to turn it into a resource, that is, I want the url to be passed as a string to a bean that I create in the context file, not convert it to an object Resource.

How can I avoid Spring resource creation?

Thanks,

Andrew

+2


a source to share


2 answers


Spring will coerce the value to the type of the property no matter what happens. If your bean has a property of Resource

that name, then Spring will try to convert the value to Resource

. If you just want the value to be as String, give your bean property a String property and Spring will pass it as-is.



+2


a source


Use an installer that takes a resource (including spring magic) and stores the resulting url, not a resource object



private String resourceUrl;

public Resource setResource(Resource resource) {
    this.resourceUrl = resource.getURL().toExternalForm();
}

      

0


a source







All Articles