3
votes

I'm not able to figure out why I am not able to inject values into my application.properties file in spring-boot. external property into the logging.file variable. I have an application.properties file which looks like this

logging.file=${mylogfile}
server.port=${myport}

with corresponding Spring-boot Application class

@PropertySources({
@PropertySource("file:///c:/myfolder/externalprops.properties"),
})

@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application {

public static void main(String[] args) throws Exception {
    SpringApplication.run(Application.class, args);
}
}

and external property file

mylogfile=myoutput.log
myport=8060

When I run my spring-boot 1.0.2.REL application I get the following exception every time I try to inject mylogfile into the logging.file property in application.properties

Exception in thread "main" java.lang.IllegalArgumentException: Could not resolve placeholder 'mylogfile' in string value "${mylogfile}"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:174)

Note that I am not having any problems injecting and starting up the application if I inject the server port number on its own.

I am going around in circles on this issue and cannot figure out what I am doing wrong.

1

1 Answers

1
votes

I don't think you can use @PropertySource to inject values into "application.properties" - the latter has to be parsed and ready to use before any @Configuration is read, or even known about. Your external properties could go in "${user.dir}/application.properties" and I think that would achieve what you are trying to do.