Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use path relative to user home in PropertySource [closed]

Spring expressions doesn't work inside the PropertySource annotation.

@PropertySource({ "classpath:application.properties",
        "#{systemProperties['user.home']}/.app.properties" })
@Configuration
public class Config {
@Bean
    public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
        PropertySourcesPlaceholderConfigurer result = new PropertySourcesPlaceholderConfigurer();
        result.setOrder(0);
        return result;
    }
}
like image 667
Daniil Iaitskov Avatar asked Mar 23 '15 16:03

Daniil Iaitskov


People also ask

What is classpath in PropertySource?

When We define property files using “classpath” as shown in above examples, it searches that file at project classpath and resolve all values. To define multiple properties file @Configuration. @PropertySource(value={"classpath:default.properties","classpath:config.properties"})

What is the use of @PropertySource annotation?

Spring @PropertySource annotation is used to provide properties file to Spring Environment. This annotation is used with @Configuration classes. Spring PropertySource annotation is repeatable, means you can have multiple PropertySource on a Configuration class.

What is Propertysources?

@PropertySource is a convenient annotation for including PropertySource to Spring's Environment and allowing to inject properties via @Value into class attributes. ( PropertySource is an object representing a set of property pairs from a particular source.) @PropertySource is used together with @Configuration .


1 Answers

You can directly use file:${user.home} to load a file under user home:

@PropertySource({ "classpath:application.properties", 
                  "file:${user.home}/.app.properties" })
@Configuration
public class Config {
}
like image 89
Rohit Jain Avatar answered Oct 25 '22 21:10

Rohit Jain