代码中使用
spring: !!!debug 模式的配置
application:
name: user-setting
userClient:
deploy-mode: unity
server:
port: 10301
servlet:
context-path: /user-setting
---
spring:: !!!k8s 模式的配置
profiles: k8s
userClient:
service:
deploy-mode: ${DEPLOY_MODE:foundry}
server:
port: 8080
使用 deploy-mode
配置
import static com.xxxx.UserSettingsConstant.*;
@Slf4j
@Service("userService")
public class UserServiceImpl implements UserService {
@Value("${userClient.deploy-mode:unity}")
private String deployMode;
@Override
public X userList(userFilterRequest request) {
....
if (deployMode.contains(UNITY_DEPLOY_MODE)) {
处理逻辑
}
....
return X;
}
package com.xxxx.setting.core;
/**
* 系统设置相关常量
*/
public class UserSettingsConstant {
public static final String UNITY_DEPLOY_MODE = "unity";
}
部署到服务器
如果是 k8s 模式
,可以设置 configMap
,新建 config-env.yml
,通过 kubectl apply -f config-env.yml
来进行 pod 的设置
config-env.yml
apiVersion: v1
kind: ConfigMap
metadata:
name: microservice-env
namespace: userClient
data:
DEPLOY_MODE: "untiy"