spring多環境變量配置 @profile

配置文件
這裏寫圖片描述

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");
    }

}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章