Skip to content

Instantly share code, notes, and snippets.

@rhoegg
Last active December 22, 2015 22:38
Show Gist options
  • Save rhoegg/6540944 to your computer and use it in GitHub Desktop.
Save rhoegg/6540944 to your computer and use it in GitHub Desktop.
Pull a string out of a file on the classpath in spring
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