Spring Boot 3.2.1 multiple .properties files per profile

188 views Asked by At

I want to have a project which allows me to have multiple profiles and also multiple configurations per profile. I want to have my general application.properties on top, and then per profile a database.properties, aws.properties, etc.

I want the following folder structure:

resources
-application.properties
-local
---database.properties
-prod
---database.properties

I tried the following on my pom.xml but it ain't working:

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>local</id>
            <properties>
                <spring.profiles.active>local</spring.profiles.active>
            </properties>
            <build>
                <resources>
                    <resource>
                        <directory>src/main/resources/local</directory>
                        <includes>
                            <include>**/*</include>
                        </includes>
                    </resource>
                </resources>
            </build>
        </profile>
        <profile>
            <id>prod</id>
            <properties>
                <spring.profiles.active>prod</spring.profiles.active>
            </properties>
            <build>
                <resources>
                    <resource>
                        <directory>src/main/resources/prod</directory>
                        <includes>
                            <include>**/*</include>
                        </includes>
                    </resource>
                </resources>
            </build>
        </profile>
    </profiles>

On my application.properties I have: [email protected]@

But the error I get is:

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource
could be configured.

Reason: Failed to determine a suitable driver class

Action:

Consider the following: If you want an embedded database (H2, HSQL or Derby), please put it on
the classpath.

If you have database settings to be loaded from a particular profile you may need to activate it 
(the profiles local are currently active).

For some reason is not picking up my database.properties.

0

There are 0 answers