Spring Boot with Maven Resource Filter (Profile)

If you want to know how to use Maven resource filter with Spring Boot, this page is for you.

This example is a part of  Spring Boot with all examples

Full Code with Spring Boot 1.5.8.RELEASE:


What you need for run this:

  • Maven 3
  • Java 8

What the code will do:

  • Call a url and it will return a value which is defined in a profile in Maven profile


This is the file structure:

Let say you have two maven profiles in pom.xml, see the yellow lines:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">



The “local” profile is for the local computer.

The “production” profile is for  the production environment.

Note: normally with Maven, you have to  have these lines in the <build> tag.


But you do not need this here because Spring Boot will take care it.

In application.properties looks like this:


Note: normally with Maven, you have to use ${database.url}, but here it is @database.url@

In TestRestController.java, it will get the property from application.properties and just return it if “/api/show” is called:

package com.surasint.example.web.api;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

public class TestRestController {

    private String sqlurl;

    public String show() {
        return sqlurl;

Key point:

  • Line 10: @Value(“${database.url}”) : it is the Spring Boot annotation to get value from application.properties.


run this in console:

mvn clean package

Then run this to start (this will use the default profile which is “local”):

mvn clean spring-boot:run

You should see something like this:

 .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 :: Spring Boot ::        (v1.5.8.RELEASE)

2017-12-12 22:03:04.243  INFO 260 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.Annotation
ConfigEmbeddedWebApplicationContext@7595f8d7: startup date [Tue Dec 12 22:03:01 CET 2017]; root of context hierarchy

Open a browser and try to go to this url:


You will get this:

Then stop the console by Ctrl + C (on Windows).

And start with this:

mvn clean spring-boot:run -Pproduction

Open a browswer and try to go to this url again:


You will get this: