# Maven profiles and Spring profiles

Similar with the former vanilla version, we can define some Maven profiles to inject configuration for different project stages, such as _dev_, _staging_, _prod_. etc.

Open the project `pom.xml` file.

```markup
<profile>
    <id>dev</id>
    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>
    <properties>
        <spring.profiles.active>dev</spring.profiles.active>
        <log4j.level>DEBUG</log4j.level>
    </properties>
    <build>
        <resources>
            <resource>
                <directory>src/main/resources-dev</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>
</profile>
```

The above Maven profile(_dev_) will be activated by default, and it will add _/src/main/reources-dev_ as resource folder.

The _application.yml_ under _/src/main/reources-dev_ will be packaged into the final package(jar or war).

We can define some other profile based _application.yml_ for different stages. Every _application.yml_ will add different configuration, such as in development stage, use a H2 database for easy testing, and in production profile, the _application.yml_ will use a pool `DataSource` for better performance at runtime.

The above approach combine Maven profiles and Spring profile to get clean and simple configuration for applications.

Alternatively, Spring Boot provides more powerful capability to switch profile via environment variables. You can package all profile based configuration in the same application package, and add a parameter to select a profile when the application is bootstrapping.

```
java -jar ./app.jar -Dspring.profiles.active=staging
```
