Last active
December 22, 2015 22:38
-
-
Save rhoegg/6540944 to your computer and use it in GitHub Desktop.
Pull a string out of a file on the classpath in spring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.foo; | |
import org.apache.commons.io.IOUtils; | |
import org.springframework.beans.factory.FactoryBean; | |
import org.springframework.core.io.Resource; | |
public class StringFromResource implements FactoryBean<String> { | |
private Resource resource; | |
public Resource getResource() { | |
return resource; | |
} | |
public void setResource(Resource resource) { | |
this.resource = resource; | |
} | |
@Override | |
public String getObject() throws Exception { | |
return IOUtils.toString(resource.getInputStream()); | |
} | |
@Override | |
public Class<?> getObjectType() { | |
return String.class; | |
} | |
@Override | |
public boolean isSingleton() { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment