【发布时间】:2019-08-18 00:08:24
【问题描述】:
我在使用 spring boot 和 maven 时遇到了一些问题。
似乎<packaging>pom</packaging> 标签添加到pom.xml 时,不知何故让spring 完全不知道父级applications.properties 配置文件。运行时,无论声明的属性如何,spring 仍然会显示横幅和信息级别的日志记录。为什么会这样?有没有办法将这些属性添加到我的父级,以便所有模块都可以在给定的配置下运行?这会成为反模式吗?
主类:
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
(父)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>
【问题讨论】:
-
你为什么将
<packaging>pom</packaging>添加到一个看起来会生成包含基于Spring Boot的应用程序的jar文件的模块中? -
该项目已初具规模,因此这是第一次尝试向其中添加许多未来模块中的一个。想法是有一个 pom 包装父模块和 jar 包装子模块。
标签: java maven spring-boot pom.xml spring-properties