Springboot not loading application.dev.properties file

application properties spring boot profiles example
spring boot application properties for dev and prod
create an application.properties file with properties fresco-course = spring boot
spring boot application.properties not loading
spring boot multiple active profiles
spring profiles xml
how to read environment specific properties file in java
spring boot development environment

In my project I want to use environment specific property file. For example if I am running it into development it should use application.dev.properties, for production it should use application.prod.properties and so on.

I have below two files in my resources folder.

  1. application.properties (For production)
  2. application.dev.properties (For development)

I have one properties like below in each file.

For Prod

server.database.host=192.168.1.1

For Dev

server.database.host=192.168.12.125 

And I have a class like below

 public class DataSource {

     @Value(${server.database.host})
     String host;

The above code always takes prod setting (application.properties) file even though I supply proper argument for dev like --spring.profiles.active=dev

Below is the command I am using to load the dev properties file.

java -jar myjar.jar --spring.profiles.active=dev

It also prints that active profile is dev but it always connect to prod db.

A few issues I noticed:

  1. @Value property name should be a String like @Value("${server.database.host}")
  2. Profile specific property files should follow application-{profile}.properties format, e.g. application-dev.properties
  3. Try passing the profile with -D like java -Dspring.profiles.active=dev -jar app.jar

When does spring use application-dev.properties vs application , Most probably some of your Run configurations in Idea have configured Spring "​profile" to run with. When you run Spring Boot application with,  I realized a couple of things now. My application.properties file is being loaded properly because I verified via the /env path (thanks Dave) that my DB properties are being loaded. The problem appears to be that when I run it using the Spring Boot maven plug-in,it fails to initialize my dataSource. mvn spring-boot:run

Try adding a vm argument in the run configuration:

-Dspring.profiles.active=dev

Spring Boot Profiles for DEV and PROD Environments, In this article, we will create a DEV profile and PROD profile to enable By default, Spring Boot parses a file called application.properties – located in the and testers load up these pages in development and test versions of the site. the next morning via email; Practice on actual problems asked by top companies, like:. Springboot not loading application.dev.properties file. 0. SpringBoot Profiles for datasource properties. 0. SpringBoot jUnit is not loading application-dev.xml. 0.

If running on Eclipse or STS, then use following steps:

  1. Right click on project -> Run As -> Run Configuration.

  2. In the new window, select spring boot application on left side, and add details on the right and in the profile dropdown, select dev.

  3. Click apply and run.

How to Use Profiles in Spring Boot, For example, in DEV, we do not need to constantly check database consistency. Let's start with setting up a Spring Boot application from the Spring Starter. But, Spring Boot — by default — provides just one property file  Configuration Properties Not Loading in Spring Boot Test. While trying to test a service layer class which loads properties from a configuration file that reads the information from either an application.yml or a application.properties, I kept running into an issue in which all of the properties were returning null.

You are supposed to specify which profile to run with as follows:

mvn spring-boot:run -Dspring-boot.run.profiles=foo,bar

Also see documentation: https://docs.spring.io/spring-boot/docs/current/maven-plugin/examples/run-profiles.html

Properties with Spring and Spring Boot, How do I load a properties file in spring boot? The application.properties file is nothing more than simple key-value storage for configuration properties. You can bundle the configuration file in your application jar or put the file in the filesystem of the runtime environment and load it on Spring Boot startup.

Reading application.properties in Spring Boot, file and class field variable will be assigned that value. With shading it works now, the package org.springframework.boot.loader is not included any more in the fat jar and also loading from external jar files on the file system works perfectly. To build a bit on what @philwebb just said, if it works with shade but not with a Spring Boot fat jar then I would consider that to be a bug. A sample project that demonstrates it working with shade and failing with a fat jar would be very useful.

Spring Boot - Application Properties, In Spring Boot, properties are kept in the application.properties file under the classpath. Note − If the property is not found while running the application, Spring Boot files for development and production to run the Spring Boot application. In this articles, we will see how to load Profile specific properties files from resource directory in Spring Boot application. Here, we set up a sample Spring Boot Project and maintains set of configuration files specific to the Profile which would be loaded when the Application runs.

Spring Boot Profiles tutorial, properties file in custom scenarios. I'm not going to discuss properties specified by the Spring Boot framework. Working with existing configuration  To notify Spring which files to use, we have to set an environment variable - spring.profiles.active. That being said, if the value of spring.profiles.active is dev, for example, Spring boot will load the application-dev.properties file and likewise. Note: application.properties is always loaded, irrespective of the spring.profiles.active value.

Comments
  • Hey thanks.. I changed the properties file name as you suggested and then the command you suggested in step 3 worked well.. Thank you so much..!
  • This doesn't seem to work any more for SpringBoot 2.0.