优化代码

This commit is contained in:
smallchill 2019-01-03 14:02:43 +08:00
parent 57d27aa0e4
commit c6eb6c7578
3 changed files with 89 additions and 36 deletions

View File

@ -27,36 +27,6 @@ public interface AppConstant {
*/
String APPLICATION_VERSION = "2.0.0";
/**
* consul dev 地址
*/
String CONSUL_DEV_HOST = "http://localhost";
/**
* consul prod 地址
*/
String CONSUL_PROD_HOST = "http://192.168.186.129";
/**
* consul端口
*/
String CONSUL_PORT = "8500";
/**
* consul端口
*/
String CONSUL_CONFIG_FORMAT = "yaml";
/**
* consul端口
*/
String CONSUL_WATCH_DELAY = "1000";
/**
* consul端口
*/
String CONSUL_WATCH_ENABLED = "true";
/**
* 基础包
*/

View File

@ -0,0 +1,79 @@
/**
* Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springblade.core.launch.consul;
/**
* Consul常量.
*
* @author Chill
*/
public interface ConsulConstant {
/**
* host key
*/
String CONSUL_HOST_KEY = "spring.cloud.consul.host";
/**
* port key
*/
String CONSUL_PORT_KEY = "spring.cloud.consul.host";
/**
* format key
*/
String CONSUL_CONFIG_FORMAT_KEY = "spring.cloud.consul.config.format";
/**
* delay key
*/
String CONSUL_WATCH_DELAY_KEY = "spring.cloud.consul.watch.delay";
/**
* enabled key
*/
String CONSUL_WATCH_ENABLEd_KEY = "spring.cloud.consul.watch.enabled";
/**
* consul dev 地址
*/
String CONSUL_DEV_HOST = "http://localhost";
/**
* consul prod 地址
*/
String CONSUL_PROD_HOST = "http://192.168.186.129";
/**
* consul端口
*/
String CONSUL_PORT = "8500";
/**
* consul端口
*/
String CONSUL_CONFIG_FORMAT = "yaml";
/**
* consul端口
*/
String CONSUL_WATCH_DELAY = "1000";
/**
* consul端口
*/
String CONSUL_WATCH_ENABLED = "true";
}

View File

@ -24,18 +24,22 @@ import java.util.Properties;
/**
* consul启动拓展
*
* @author smallchil
* @author Chill
*/
public class ConsulLauncherServiceImpl implements LauncherService {
@Override
public void launcher(SpringApplicationBuilder builder, String appName, String profile) {
Properties props = System.getProperties();
props.setProperty("spring.cloud.consul.host", profile.equals(AppConstant.DEV_CDOE) ? AppConstant.CONSUL_DEV_HOST : AppConstant.CONSUL_PROD_HOST);
props.setProperty("spring.cloud.consul.port", AppConstant.CONSUL_PORT);
props.setProperty("spring.cloud.consul.config.format", AppConstant.CONSUL_CONFIG_FORMAT);
props.setProperty("spring.cloud.consul.watch.delay", AppConstant.CONSUL_WATCH_DELAY);
props.setProperty("spring.cloud.consul.watch.enabled", AppConstant.CONSUL_WATCH_ENABLED);
if (props.getProperty(ConsulConstant.CONSUL_HOST_KEY) == null) {
props.setProperty(ConsulConstant.CONSUL_HOST_KEY, profile.equals(AppConstant.DEV_CDOE) ? ConsulConstant.CONSUL_DEV_HOST : ConsulConstant.CONSUL_PROD_HOST);
}
if (props.getProperty(ConsulConstant.CONSUL_PORT_KEY) == null) {
props.setProperty(ConsulConstant.CONSUL_PORT_KEY, ConsulConstant.CONSUL_PORT);
}
props.setProperty(ConsulConstant.CONSUL_CONFIG_FORMAT_KEY, ConsulConstant.CONSUL_CONFIG_FORMAT);
props.setProperty(ConsulConstant.CONSUL_WATCH_DELAY_KEY, ConsulConstant.CONSUL_WATCH_DELAY);
props.setProperty(ConsulConstant.CONSUL_WATCH_ENABLEd_KEY, ConsulConstant.CONSUL_WATCH_ENABLED);
}
}