我有一个包含两个模块(搜索和用户管理)的存储库.我希望两个模块都有自己的application.properties.

├───pom.xml
├───search
│   ├───src
│   │   ├───main
│   │   │   ├───java
│   │   │   │   └───com
│   │   │   │       └───example
│   │   │   │           └───projectname
│   │   │   │               └───search
│   │   │   │                   ├───controller
│   │   │   │                   ├───model
│   │   │   │                   ├───query
│   │   │   │                   └───Main.class
│   │   │   └───resources
│   │   └───test
│   │       └───src
│   ├───pom.xml
│   └───target
├───target
└───usermanagement
    ├───src
    │   └───com
    │       └───example
    │           └───projectname
    │               └───usermanagement
    ├───test
    │   └───src
    └───pom.xml

resources搜索目录有一个应用程序.包含以下内容的属性:

spring.profiles.active=dev

未使用此选项.我必须手动更新我的运行配置文件,并用应用程序的绝对路径通过spring.config.additional-location.属性.

父母的pom

    <dependencyManagement>
        <dependencies>
            <!-- Springboot -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
                <version>2.7.1</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
                <version>2.7.1</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.7.1</version>
            <type>pom</type>
        </dependency>
    </dependencies>
    <build>
        <sourceDirectory>src/main/java</sourceDirectory>
        <testSourceDirectory>src/test</testSourceDirectory>
        <defaultGoal>clean test install</defaultGoal>
    </build>
    <modules>
        <module>search</module>
        <module>usermanagement</module>
    </modules>

搜索子对象的pom

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

    <build>
        <plugins>
            <!-- Build jar with dependencies -->
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>main.java.com.example.projectname.search.Main</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>

我已经try 在parent和@PropertyScan中添加src/main/resources.

推荐答案

通过将此添加到家长pom中,我能够解决我的问题

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

Java相关问答推荐

Java 21虚拟线程会解决转向react 式单线程框架的主要原因吗?

try 使用Java 9或更高版本对特殊对象图进行解析时出现NullPointerException

使用java访问具体子类特定方法的最佳方法是什么?

通过Spring Security公开Spring Boot执行器端点

使用Jolt将字段转换为列表

在添加AdMob时无法为Google Play构建应用程序包:JVM垃圾收集器崩溃和JVM内存耗尽

在执行流和相关操作时,使用Java泛型为2个方法执行相同的操作,但对象不同

虚拟线程应该很快消亡吗?

SpringBoot:在条件{Variable}.isBlank/{Variable}.isEmpty不起作用的情况下进行路径变量验证

来自外部模块的方面(对于Java+Gradle项目)不起作用

垃圾回收器是否真的删除超出作用域的对象?

Spring Boot中的应用程序.properties文件中未使用的属性

具有多个模式的DateTimeForMatter的LocalDate.parse失败

将java.util.Date(01.01.0001)转换为java.time.LocalDate将返回29.12.0000

不能在 map 上移除折线

如何在Java中的重写方法参数中强制(Enum)接口实现?

根据应用程序 Select 的语言检索数据

如何在Spring Boot中为不同的部署环境管理多个.properties文件?

如何使用java区分以下结果

如何解释泛型类层次 struct 中子类的返回值类型和参数定义?