SpringBoot (nineteen) _spring.profiles.active = Use the @ profiles.active @

The company is now in use [email protected]@when I saw this when, blinded look, this @is what means.

In fact, here it is fit maven profileto select different profiles for development

Real

1. Build a project springboot

As used herein, the idea to build, this process is omitted

2.pom file configuration

<profiles>
        <profile>
            <!-- 生产环境 -->
            <id>prod</id>
            <properties>
                <profiles.active>prod</profiles.active>
            </properties>
        </profile>
        <profile>
            <!-- 本地开发环境 -->
            <id>dev</id>
            <properties>
                <profiles.active>dev</profiles.active>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <!-- 测试环境 -->
            <id>test</id>
            <properties>
                <profiles.active>test</profiles.active>
            </properties>
        </profile>
    </profiles>
  • Here dev default configuration

3. Configure multiple profiles

application.properties

Note here the correspondence to and pom file profiles.active

[email protected]@

application-dev.properties

name = "dev"

application-prod.properties

name = "prod"

application-test.properties

name = "test"

4. Write a test controller


/**
 * @author kevin
 * @date 2019/6/28 16:12
 */
@RestController
public class HelloController {

    @Value("${name}")
    private String name;

    @RequestMapping(value = {"/hello"},method = RequestMethod.GET)
    public String say(){
        return name;
    }
}

5. Start Testing

Use the idea to start development tools

Dev default, if you want to use prod profile, as FIG selected prod, note the following introduction to restart the project

D:\dev_code\profiles-demo\target>curl http://localhost:8080/hello
"prod"

6 pack

As used herein idea is no longer packaged presentation, if you use the command

mvn clean package -P dev

Dev is the use configuration

Well, have fun

Guess you like

Origin www.cnblogs.com/zhenghengbin/p/11103998.html