Evandro Teixeira
Evandro Teixeira

Reputation: 370

Spring boot properties vs maven pom packaging tag

I have been facing some problems with spring boot and maven.

It seems that the <packaging>pom</packaging> tag, when added to pom.xml, somehow makes spring completely unaware of the parent-level applications.properties configuration file. When running, spring still will show the banner and info-level logging regardless of the properties stated. Why would that be the case? Is there a way to add those properties to my parent such that all modules would operate under given configuration? Would this become an anti-pattern?

Main class:

package com.example.app; //could also be inside the app-client module

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}

application.properties:

spring.main.banner-mode=off
logging.level.root=info

(parent) pom.xml:


<?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">
    <modelVersion>4.0.0</modelVersion>
    <packaging>pom</packaging>
    <modules>
        <module>app-client</module>
    </modules>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example.</groupId>
    <artifactId>app</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>app</name>
    <description>Demo app</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>


Upvotes: 1

Views: 1467

Answers (1)

mle
mle

Reputation: 2542

Totally agreeing with the comment of Andy on your question I like to point out, that the use of the packaging type pom is appropriate if you want to denote an artifact as some kind of module container are base project where you collect dependency information for your (sub-)modules.

However the @SpringBootApplication in your case shows us that you want to use your artifact for running business code. That on the other hand leads to packaging types like jar or war. Switch it to one of them and everything should run fine.

For more information please consult also the Maven reference for packaging.

Upvotes: 2

Related Questions