Additional Configurations In Spring Boot Application

Additional Config

Here I am going to tell about additional config or configurations in your spring boot application. Now what could be the additional configurations in your spring boot application. Generally you define configurations into file under class path folder.

But what if your application needs more configurations which could be supplied during runtime or the jar which is produced from this spring boot application can be used into other application and the other application already provides those additional configurations. So, you don’t need to define these additional configurations into the file.

In this situation you may provide another properties file location with the spring’s standard variable SPRING_CONFIG_ADDITIONAL_LOCATION and all key/value pairs will be picked up by the spring boot application.

For example, in Eclipse IDE you can specify the additional properties file in the Run Configurations window under Environment tab. This Run Configurations window you can find by doing right click on the main class.

spring additional config


Java 19, Maven 3.8.5, Spring Boot 3.0.6/3.1.0

Build File

The following pom.xml build file can be used as a reference for the example.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi=""

Application Config

The following src/main/resources/ file contains the regular application configuration key/value pair(s).


Additional Config

The additional configuration can be defined in a properties file which is not available in the spring boot application’s class path folder. The following content is kept into a file called file and you can place it anywhere in the system.


Inject Config

You need to inject the same way you inject key from file. For example, let look at the following main class where I have injected all keys from regular and additional config files.

public class App implements CommandLineRunner {
	private int port;

	private String hi;

	private String hello;

	public static void main(String[] args) {, args);

	public void run(String... args) throws Exception {
		System.out.println("server.port => " + port);
		System.out.println("hi => " + hi + ", hello => " + hello);


Make sure you specify the location of the additional config file using the standard spring variable name.

Testing Additional Config

If you do not specify the additional config file then you will see the following exception:

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'hi' in value "${hi}"

If you specify the additional config file then you will see the following output:

server.port => 8080
hi => Hi, hello => Hello

Source Code


Leave a Reply

Your email address will not be published. Required fields are marked *