配置文件
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");
}
}