spring多环境变量配置 @profile

xiaoxiao2021-02-28  108

配置文件

dev 开发环境 prod 生产环境

//application.properties文件内 spring.profiles.active=(环境变量:dev就是开发环境;prod就是生产)

@profile

//在conroller里面注入 根据不同的环境变量 执行不同的代码 package com.supergk.core.index; /** * Created by LM on 2017/8/6. */ public interface demo { public void ss(); } package com.supergk.core.index; import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Service; /** * Created by LM on 2017/8/6. */ @Service("demo") @Profile("dev") public class Demoimpl1 implements demo{ public void ss() { System.out.println("22222"); } } package com.supergk.core.index; import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Service; /** * Created by LM on 2017/8/6. */ @Service("demo") @Profile("prod") public class Demoimpl2 implements demo{ public void ss() { System.out.println("1111"); } }
转载请注明原文地址: https://www.6miu.com/read-44444.html

最新回复(0)