Java How to read files from root dir using ClassPathResource

Viewed 43

I'm building a spring application, and I'm running my app in a container

I have the properties file in the container filesystem. But I can't load it with - ClassPathResource.

How can i add Resource to a file, and not class path resource?

@Bean("propertyConfigurer")
public static PropertySourcesPlaceholderConfigurer propertyConfigurer() throws IOException {
    PropertySourcesPlaceholderConfigurer propertyConfigurer = new DatoramaPropertySourcesConfigurer();
    List<Resource> resources = Lists.newArrayList();
    resources.add(new ClassPathResource("/Users/test/web.properties"));
    propertyConfigurer.setLocations(FluentIterable.from(resources).toArray(Resource.class));
    propertyConfigurer.setIgnoreResourceNotFound(false);
    return propertyConfigurer;
}
1 Answers

Solved by

resources.add(new FileUrlResource("/Users/test/web.properties"));
Related