RunningConfig support get from spring.properties configuration file

This commit is contained in:
pbting 2019-08-06 16:43:48 +08:00
parent da8e09ff4b
commit 19a5ac632c
4 changed files with 21 additions and 22 deletions

View File

@ -1,22 +1,15 @@
# spring
server.contextPath=/nacos
server.servlet.contextPath=/nacos
server.servlet.context-path=/nacos
server.port=8848
nacos.cmdb.dumpTaskInterval=3600
nacos.cmdb.eventTaskInterval=10
nacos.cmdb.labelTaskInterval=300
nacos.cmdb.loadDataAtStart=false
# metrics for prometheus
#management.endpoints.web.exposure.include=*
# metrics for elastic search
management.metrics.export.elastic.enabled=false
#management.metrics.export.elastic.host=http://localhost:9200
# metrics for influx
management.metrics.export.influx.enabled=false
#management.metrics.export.influx.db=springboot
@ -24,17 +17,14 @@ management.metrics.export.influx.enabled=false
#management.metrics.export.influx.auto-create-db=true
#management.metrics.export.influx.consistency=one
#management.metrics.export.influx.compressed=true
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D
# default current work dir
server.tomcat.basedir=
## spring security config
### turn off security
#spring.security.enabled=false
#management.security=false
#security.basic.enabled=false
#nacos.security.ignore.urls=/**
nacos.security.ignore.urls=/,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/login,/v1/console/health/**,/v1/cs/**,/v1/ns/**,/v1/cmdb/**,/actuator/**,/v1/console/server/**

View File

@ -33,7 +33,7 @@ public interface Constants {
*/
String STANDALONE_MODE_PROPERTY_NAME = "nacos.standalone";
/**
/**
* The System property name of Function mode
*/
String FUNCTION_MODE_PROPERTY_NAME = "nacos.functionMode";
@ -43,6 +43,11 @@ public interface Constants {
*/
String PREFER_HOSTNAME_OVER_IP_PROPERTY_NAME = "nacos.preferHostnameOverIp";
/**
* the root context path
*/
String ROOT_WEB_CONTEXT_PATH = "/";
String NACOS_SERVER_IP = "nacos.server.ip";
String USE_ONLY_SITE_INTERFACES = "nacos.inetutils.use-only-site-local-interfaces";
@ -51,4 +56,5 @@ public interface Constants {
String IP_ADDRESS = "nacos.inetutils.ip-address";
String PREFER_HOSTNAME_OVER_IP = "nacos.inetutils.prefer-hostname-over-ip";
String SYSTEM_PREFER_HOSTNAME_OVER_IP = "nacos.preferHostnameOverIp";
String WEN_CONTEXT_PATH = "server.servlet.context-path";
}

View File

@ -15,6 +15,8 @@
*/
package com.alibaba.nacos.naming.boot;
import com.alibaba.nacos.core.utils.Constants;
import com.alibaba.nacos.core.utils.PropertyUtil;
import com.alibaba.nacos.naming.misc.Loggers;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -37,6 +39,8 @@ public class RunningConfig implements ApplicationListener<WebServerInitializedEv
@Autowired
private ServletContext servletContext;
private static volatile boolean isServerInitialized = false;
@Override
public void onApplicationEvent(WebServerInitializedEvent event) {
@ -45,10 +49,7 @@ public class RunningConfig implements ApplicationListener<WebServerInitializedEv
serverPort = event.getWebServer().getPort();
contextPath = servletContext.getContextPath();
if (StringUtils.isEmpty(contextPath)) {
// set the root context path
contextPath = "/";
}
isServerInitialized = true;
}
public static int getServerPort() {
@ -57,6 +58,14 @@ public class RunningConfig implements ApplicationListener<WebServerInitializedEv
public static String getContextPath() {
if (!isServerInitialized) {
String contextPath = PropertyUtil.getProperty(Constants.WEN_CONTEXT_PATH);
if (Constants.ROOT_WEB_CONTEXT_PATH.equals(contextPath)) {
return StringUtils.EMPTY;
} else {
return contextPath;
}
}
return contextPath;
}
}

View File

@ -1,18 +1,13 @@
server.port=8848
server.servlet.context-path=/nacos
# Number of ms to wait before throwing an exception if no connection is available.
spring.datasource.max-wait=10000
# Maximum number of active connections that can be allocated from this pool at the same time.
spring.datasource.max-active=15
## Validate the connection before borrowing it from the pool.
#spring.datasource.test-on-borrow=true
management.metrics.export.elastic.enabled=false
#management.metrics.export.elastic.host=http://localhost:9200
# metrics for influx
management.metrics.export.influx.enabled=false
#management.metrics.export.influx.db=springboot
@ -20,7 +15,6 @@ management.metrics.export.influx.enabled=false
#management.metrics.export.influx.auto-create-db=true
#management.metrics.export.influx.consistency=one
#management.metrics.export.influx.compressed=true
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D
# default current work dir