I have an application which is deployed as jar and is executed by some other parent application. The parent application has defined a log4j configuration file and the file is mentioned while starting the parent application.
When I am trying to use log4j instance for child application, its configuration file is never picked. How can I use a different configuration file for my application without impacting configuration file of the parent application?
Related
I have a setup of a Springboot applications with multiple profiles. I am trying to include the setup of profile in jar itself and remove it from the server side. However, after every release Spring creates a sub directory with /config including all my application-*.yml files. How can I disable the default creation of this folder?
I do not require the /config folder as I am using nssm service and providing which profile to use in the argument line.
I have the below configuration in xml of an maven dependency jar.
context:property-placeholder location="file:/dir/project.properties"/>
Unfortunately I can't create that folder in my machine and can't modify dependency code too. So when I am running the parent app, I want to override the location of properties file or provide external properties file.
Both parent and child are developed using Spring Core. (It's not Spring Boot). Parent is War and child is jar.
According to Spring Context lifecycle, if it uses Spring Cloud Context, the Spring application first loads configuration from bootstrap.properties, then starts and then loads application.properties (in your case project.properties).
You can add to the project dependencies the Spring Cloud dependency. Specifying classpath (or using default config folder) you can have properties in another place.
I have a spring boot 2 application with 2 property files:
application.properties
application-dev.properties
When I run the application in IntellijIdea using the dev profile, Spring reads both the profile specific file and the default file.
Once I build an executable jar file, I created a new application-prod.properties outside of the jar, with production environment properties and execute the application with --spring.profiles.active=prod expecting it to read this file AND the default application.properties, but it is only reading the file outside the jar (application-prod.properties).
Should Spring Boot read both files or am I expecting something that it does not do by default?
If it should, what can I be missing?
As mentioned by Michael, Spring boot supports property hierarchies.
I tried this and it works as expected, you can find a reference project in here
A few things that I can think about:
Extract the contents of your jar file and confirm that the file named application.properties is bundled in there.
You may be overwriting the spring.config.location property and using filenames instead of directories
From Spring Boot documentation
If you have specified any files in spring.config.location, profile-specific variants of those files are not considered. Use directories in spring.config.location if you want to also use profile-specific properties.
If you override the default spring.config.location then the application may not be able to find the default application.properties file.
By default, application.properties will be used to run the Spring Boot application. While running the JAR file, you need to specify the spring active profile. only one file will be read
I have Spring configured to look up a conf/database.properties file to load some configuration.
This works well outside Tomcat, and in Junit tests, but in Tomcat, it never load. Below the images of this problem.
Configurations:
And:
The properties file in project folder:
The parameters to run Tomcat inside Eclipse:
The temp0 Tomcat Folder, where is all the files being generated Ok:
The Tomcat error log:
https://gist.github.com/4060538
I solved the problem. I think I was using spring in the wrong way.
I changed the follow:
In the library I'm importing/referencing, I removed the line where was importing database.properties file.
I created a spring.xml in my main web app, where in this file I imported the database.properties file and the other app-context.xml files I need to reference.
I think Spring spring don't load properties file outside of the jar. You need to load properties file locally in you main application, and so, references another spring-context.xml files needed.
maven module spring application.
1 module is a spring mvc application, another is a non-web but spring managed application.
In my project root, I have:
/src/main/conf
This folder contains my non-web managed spring xml configuration. I added this folder to my class path in intellij.
IntelliJ doesn't pickup the file correctly, meaning I don't get code completion or anything (allot of the names etc. are in bold red i.e. intellij is telling me something is wrong). Can this be fixed somehow?
I have kept my spring mvc config file inside its module (not in the conf folder) because the code completion doesn't work and it's a pain to work with without the IDE helping. But it makes managing things during deployment harder.
In both of my spring config files (for the web app and non-web app), I have my dataSource settings hard-coded in the file, I want to extract this somehow into a properties file, how can I do this?
1 - You can have different spring configuration files all in the same folder, just you need to use different names form them. So, I would use src/main/resources instead to create a new folder in the maven project structure. You will avoid problems.
2- Datasource in both files? why? If you have already two spring configuration files, I would create a third one (application-context-dao.xml) and share the dataSource. How to move properties to a configuration file? See.