LauncherServiceImpl.java 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * BladeX Commercial License Agreement
  3. * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
  4. * <p>
  5. * Use of this software is governed by the Commercial License Agreement
  6. * obtained after purchasing a license from BladeX.
  7. * <p>
  8. * 1. This software is for development use only under a valid license
  9. * from BladeX.
  10. * <p>
  11. * 2. Redistribution of this software's source code to any third party
  12. * without a commercial license is strictly prohibited.
  13. * <p>
  14. * 3. Licensees may copyright their own code but cannot use segments
  15. * from this software for such purposes. Copyright of this software
  16. * remains with BladeX.
  17. * <p>
  18. * Using this software signifies agreement to this License, and the software
  19. * must not be used for illegal purposes.
  20. * <p>
  21. * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
  22. * not liable for any claims arising from secondary or illegal development.
  23. * <p>
  24. * Author: Chill Zhuang (bladejava@qq.com)
  25. */
  26. package org.springblade.common.launch;
  27. import org.springblade.common.constant.LauncherConstant;
  28. import org.springblade.core.auto.service.AutoService;
  29. import org.springblade.core.launch.service.LauncherService;
  30. import org.springblade.core.launch.utils.PropsUtil;
  31. import org.springframework.boot.builder.SpringApplicationBuilder;
  32. import java.util.Properties;
  33. /**
  34. * 启动参数拓展
  35. *
  36. * @author smallchil
  37. */
  38. @AutoService(LauncherService.class)
  39. public class LauncherServiceImpl implements LauncherService {
  40. @Override
  41. public void launcher(SpringApplicationBuilder builder, String appName, String profile, boolean isLocalDev) {
  42. Properties props = System.getProperties();
  43. // 指定注册配置信息
  44. PropsUtil.setProperty(props, "spring.cloud.nacos.username", LauncherConstant.NACOS_USERNAME);
  45. PropsUtil.setProperty(props, "spring.cloud.nacos.password", LauncherConstant.NACOS_PASSWORD);
  46. PropsUtil.setProperty(props, "spring.cloud.nacos.discovery.server-addr", LauncherConstant.nacosAddr(profile));
  47. PropsUtil.setProperty(props, "spring.cloud.nacos.config.server-addr", LauncherConstant.nacosAddr(profile));
  48. PropsUtil.setProperty(props, "spring.cloud.sentinel.transport.dashboard", LauncherConstant.sentinelAddr(profile));
  49. PropsUtil.setProperty(props, "spring.zipkin.base-url", LauncherConstant.zipkinAddr(profile));
  50. // 开启多数据源
  51. PropsUtil.setProperty(props, "spring.datasource.dynamic.enabled", "true");
  52. // 指定注册IP
  53. // PropsUtil.setProperty(props, "spring.cloud.nacos.discovery.ip", "127.0.0.1");
  54. // 指定注册端口
  55. // PropsUtil.setProperty(props, "spring.cloud.nacos.discovery.port", "8200");
  56. // 自定义命名空间
  57. PropsUtil.setProperty(props, "spring.cloud.nacos.config.namespace", LauncherConstant.NACOS_NAMESPACE);
  58. PropsUtil.setProperty(props, "spring.cloud.nacos.discovery.namespace", LauncherConstant.NACOS_NAMESPACE);
  59. // 自定义分组
  60. // PropsUtil.setProperty(props, "spring.cloud.nacos.config.group", NacosConstant.NACOS_CONFIG_GROUP);
  61. // PropsUtil.setProperty(props, "spring.cloud.nacos.discovery.group", NacosConstant.NACOS_CONFIG_GROUP);
  62. }
  63. }