I was using spring boot 1.4.0 there everything was working fine but I updated spring boot to 1.4.2 and booom following exception occurred.
IllegalArgumentException: Could not resolve placeholder 'example.property' in string value "${example.property}"
Again I downgrade version to 1.4.0 it was working.
I have placed properties file outside jar and I used spring.config.location to provide example.yml file path where I kept properties with help of STS(eclipse) run configuration.
Parameter Name : spring.config.location
Value : file:/home/project/application-property.yml,file:/home/project/email-property.yml
Following is usage of property in spring,
#Service("myService")
public class MyServiceImpl implements MyService {
#Value("${example.property}")
private String someProperty;
....
}
Following is my application class (not single xml file I have used for config),
#SpringBootApplication
public class WebApplication
{
public static void main(String[] args)
{
SpringApplication.run(WebApplication.class, args);
}
}
Is there any changes in spring-boot 1.4.2 related properties access. What should I do to make it work?
Following solution worked for me,
STS/eclipse run configuration added run time parameters,
Parameter Name : run.arguments
Value : "--spring.config.location=file:/home/project/application-property.yml", "--spring.config.location=file:/home/project/mail-property.yml"
NOTE : If you look values its double quoted comma seperated list of files
But really don't know why this solution is working and not one in question. Please do comment if know reason for this.
Related
In our Springboot MVC project we need to get context path. The following code works fine if we use embedded tomcat. Otherwise if we deploy war file to jboss server, context path returns null.
I tried to add context-root property to jboss-web.xml but changed nothing. I also tried to add "server.servlet.contextPath" property to application.properties file but it doesn't work.
Spring boot version : 2.2.0.RELEASE
Code:
#Configuration
public class EurekaClientConfigBeanListener implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
String pathValue = System.getProperty("server.servlet.contextPath");
}
I have two configuration files that have to be read using spring boot application, however, only the first configuration property file is resolved (external_application.properties) , later one (queries_config.properties) is not getting detected any issue in passing in the command line.
java -Dexternal.app.properties=file:external_application.properties -Dqueries.config.properties=file:queries_config.properties -jar testsnapshot.jar
If you are using spring boot so you can use
java
-Dspring.config.location=file:external_application.properties,file:queries_config.properties
source
I did like below which resolved over all problem..
java -Dspring.config.location=classpath:file:///C:\Users\configfiles\ -jar testsnapshot.jar
secondly to lookup for external config
#Component
#PropertySource(value = "${spring.config.location}queries_config-${spring.profiles.active}.properties")
#ConfigurationProperties("query")
public class QueriesConfig {
}
#Component
#PropertySource(value = "${spring.config.location}external_application-${spring.profiles.active}.properties")
#ConfigurationProperties("query")
public class ExternalConfig {
}
I have a spring boot application and the setting file with the below annotation.
#ConfigurationProperties("test.prop")
public class TestPropSettings {
private String name;
}
The following property in the application.properties set this value.
test.prop.name=XYZ
But, I would like to pass thru program arguments without having the property file.
Tried with,
-Dtest.prop.name=XYZ in eclipse program arguments. But, it does not work. Is there any other way?
Thanks
If you start your jar directly, you can override the property like this:
java -jar your-app.jar --test.prop.name=XYZ
In Eclipse you also need to pass --test.prop.name=XYZ in you program arguments.
I'm trying to convert a traditional Tomcat Spring MVC webapp to Spring Boot. The new application should still use .war deployment.
For various reasons I have the obligatory requirement that the application.properties file resides inside a WEB-INF/conf folder in the deployed app and NOT inside the WEB-INF/classes folder where Spring Boot puts it by default.
In the original webapp I could put the application.properties file inside the src/main/webapp/WEB-INF/conf folder (so they get copied to WEB-INF/conf in the deployed application) and then use it like this:
<context:property-placeholder location="/WEB-INF/conf/application.properties"/>
What is the Spring Boot way to refer to this location?
I tried adding each of the following:
spring.config.location=WEB-INF/conf/application.properties
but my application.properties file still doesn't get loaded.
What finally worked was the following #PropertySource annotation.
#SpringBootApplication
#PropertySource(value = {"WEB-INF/conf/application.properties"})
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
It seems that not specifying classpath: or file: at the beginning of a path makes it use a path relative to the webapp.
I'm still not sure as to why specifying
spring.config.location=WEB-INF/conf/application.properties
didn't have the same effect.
I have a strange problem. I made a Spring Batch application configurated and launched with Spring Boot. All my unit tests are passing.
But when I run program from command line :
java -cp "./batch-1.0-SNAPSHOT-jar-with-dependencies.jar:." com.batch.BatchApplication
I got a No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate].
If I run the same main class from Eclipse, all is working.
public class BatchApplication {
/**
* #param args
*/
public static void main(String[] args) throws Exception {
System.exit(SpringApplication.exit(SpringApplication.run(BatchConfiguration.class, args)));
}
}
Spring Boot "auto configuration" seems not working using command line.
Could you help me ?
Try java -jar your-long-name.jar (like in the docs and all the examples and guides). It uses a different main and makes the dependencies available at runtime.