美文网首页
Spring Boot 不同环境下的配置

Spring Boot 不同环境下的配置

作者: 刘玉秀888 | 来源:发表于2018-11-25 11:08 被阅读0次

开发、测试和生产环境

可以定义多个环境配置文件
application-{xxx}.properties


image.png

使用参数控制激活的环境

java -jar LearnSpringBoot-0.0.1-SNAPSHOT.jar --spring.profiles.active=dev

使用注解控制激活的环境

@ActiveProfiles("test")

使用注解来限制环境,这段代码只有在dev环境被激活的情况下才生效


@Profile(value = "dev")
@Service
public class ProfileDevServiceImpl implements ProfileService {
 
    public ProfileDevServiceImpl() {
 
        System.out.println("我是开发环境。。。。。");
    }
 
    @Override
    public String getProfileDomain() {
        StringBuilder sb = new StringBuilder();
        sb.append("我在开发环境,").append("我只能吃加班餐:大米饭。。。。");
        return sb.toString();
    }
}

相关文章

网友评论

      本文标题:Spring Boot 不同环境下的配置

      本文链接:https://www.haomeiwen.com/subject/tqnhqqtx.html