服务端web端口支持启动参数指定
This commit is contained in:
@@ -23,11 +23,16 @@
|
||||
package fun.asgc.neutrino.core.context;
|
||||
|
||||
import fun.asgc.neutrino.core.base.event.SimpleApplicationEventManager;
|
||||
import fun.asgc.neutrino.core.util.ArrayUtil;
|
||||
import fun.asgc.neutrino.core.util.LockUtil;
|
||||
import fun.asgc.neutrino.core.util.StringUtil;
|
||||
import fun.asgc.neutrino.core.util.SystemUtil;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -69,4 +74,49 @@ public class Environment {
|
||||
* 默认的应用事件管理器
|
||||
*/
|
||||
private SimpleApplicationEventManager defaultApplicationEventManager;
|
||||
/**
|
||||
* 参数map
|
||||
*/
|
||||
private Map<String, String> mainArgsMap = null;
|
||||
|
||||
private Map<String, String> getMainArgsMap() {
|
||||
return LockUtil.doubleCheckProcessForNoException(
|
||||
() -> null == mainArgsMap,
|
||||
this,
|
||||
() -> {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
if (ArrayUtil.notEmpty(mainArgs)) {
|
||||
for (String param : mainArgs) {
|
||||
if (!StringUtil.isEmpty(param)) {
|
||||
int index = param.indexOf("=");
|
||||
if (index > 0 && index < param.length() - 1) {
|
||||
String key = param.substring(0, index);
|
||||
String val = param.substring(index + 1);
|
||||
map.put(key, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
mainArgsMap = map;
|
||||
},
|
||||
() -> mainArgsMap
|
||||
);
|
||||
}
|
||||
|
||||
private String getMainArgs(String key) {
|
||||
return getMainArgsMap().get(key);
|
||||
}
|
||||
|
||||
public Integer getMainArgsForInteger(String key) {
|
||||
String val = getMainArgs(key);
|
||||
Integer res = null;
|
||||
try {
|
||||
if (!StringUtil.isEmpty(val)) {
|
||||
res = Integer.valueOf(val);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-1
@@ -28,6 +28,7 @@ import fun.asgc.neutrino.core.annotation.NonIntercept;
|
||||
import fun.asgc.neutrino.core.bean.BeanWrapper;
|
||||
import fun.asgc.neutrino.core.bean.factory.SimpleBeanFactory;
|
||||
import fun.asgc.neutrino.core.context.ApplicationConfig;
|
||||
import fun.asgc.neutrino.core.context.Environment;
|
||||
import fun.asgc.neutrino.core.util.*;
|
||||
import fun.asgc.neutrino.core.web.annotation.RestController;
|
||||
import fun.asgc.neutrino.core.web.config.WebMvcConfigurer;
|
||||
@@ -59,6 +60,8 @@ public class WebContextHolder {
|
||||
private ApplicationConfig applicationConfig;
|
||||
@Autowired
|
||||
private SimpleBeanFactory applicationBeanFactory;
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
@Init
|
||||
public void init() {
|
||||
@@ -68,7 +71,10 @@ public class WebContextHolder {
|
||||
initMaxContentLength();
|
||||
initControllerBeanWrapperList();
|
||||
initInterceptorRegistry();
|
||||
port = http.getPort();
|
||||
port = environment.getMainArgsForInteger("port");
|
||||
if (null == port) {
|
||||
port = http.getPort();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getHttpContextPath() {
|
||||
|
||||
Reference in New Issue
Block a user