Merge branch 'dev' of github.com:nutzam/nutzboot into dev

This commit is contained in:
Wendal Chen 2021-05-11 15:03:31 +08:00
commit d64d1f80b3
No known key found for this signature in database
GPG Key ID: E7354FE43E95013E
7 changed files with 122 additions and 75 deletions

View File

@ -10,10 +10,7 @@ import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.yaml.snakeyaml.Yaml;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@ -61,7 +58,7 @@ public class YamlConfigureLoader extends AbstractConfigureLoader {
// 加载指定profile,如果有的话
if (conf.has("nutz.profiles.active")) {
String profile = conf.get("nutz.profiles.active");
String _path = path.substring(0, path.lastIndexOf('.')) + "-" + profile + ".yml";
String _path = path.substring(0, path.lastIndexOf('.')) + "-" + profile + ".yaml";
readYamlPath(_path);
}
// 如果conf内含有nutz.boot.configure.yaml.dir配置则读取该目录下的所有配置文件
@ -87,7 +84,7 @@ public class YamlConfigureLoader extends AbstractConfigureLoader {
if (Strings.isBlank(conf.get("app.build.version"))) {
InputStream ins = resourceLoader.get("build.version");
if (ins != null) {
yamlToProperties(new Yaml().loadAs(Streams.utf8r(ins), Map.class));
conf.load(new InputStreamReader(ins), false);
}
}
}

View File

@ -60,17 +60,22 @@
<dependency>
<groupId>com.netflix.ribbon</groupId>
<artifactId>ribbon-loadbalancer</artifactId>
<version>2.2.4</version>
<version>2.7.18</version>
</dependency>
<dependency>
<groupId>com.netflix.ribbon</groupId>
<artifactId>ribbon-core</artifactId>
<version>2.2.4</version>
<version>2.7.18</version>
</dependency>
<dependency>
<groupId>com.netflix.ribbon</groupId>
<artifactId>ribbon-archaius</artifactId>
<version>2.7.18</version>
</dependency>
<dependency>
<groupId>com.netflix.ribbon</groupId>
<artifactId>ribbon-eureka</artifactId>
<version>2.2.4</version>
<version>2.7.18</version>
<scope>provided</scope>
</dependency>
</dependencies>

View File

@ -1,40 +1,27 @@
package org.nutz.boot.starter.nacos;
import static com.alibaba.nacos.api.PropertyKeyConst.ACCESS_KEY;
import static com.alibaba.nacos.api.PropertyKeyConst.CLUSTER_NAME;
import static com.alibaba.nacos.api.PropertyKeyConst.CONFIG_LONG_POLL_TIMEOUT;
import static com.alibaba.nacos.api.PropertyKeyConst.CONFIG_RETRY_TIME;
import static com.alibaba.nacos.api.PropertyKeyConst.CONTEXT_PATH;
import static com.alibaba.nacos.api.PropertyKeyConst.ENABLE_REMOTE_SYNC_CONFIG;
import static com.alibaba.nacos.api.PropertyKeyConst.ENCODE;
import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT;
import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT_PORT;
import static com.alibaba.nacos.api.PropertyKeyConst.MAX_RETRY;
import static com.alibaba.nacos.api.PropertyKeyConst.NAMESPACE;
import static com.alibaba.nacos.api.PropertyKeyConst.SECRET_KEY;
import static com.alibaba.nacos.api.PropertyKeyConst.SERVER_ADDR;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.Executor;
import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.config.ConfigService;
import org.nutz.boot.AppContext;
import org.nutz.boot.annotation.PropDoc;
import org.nutz.boot.config.impl.PropertiesConfigureLoader;
import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.json.Json;
import org.nutz.json.JsonFormat;
import org.nutz.lang.Lang;
import org.nutz.lang.Strings;
import org.nutz.lang.stream.StringInputStream;
import org.nutz.lang.util.NutMap;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.yaml.snakeyaml.Yaml;
import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.config.ConfigService;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.Executor;
import static com.alibaba.nacos.api.PropertyKeyConst.*;
/**
* @author wentao
@ -45,8 +32,8 @@ import com.alibaba.nacos.api.config.ConfigService;
* @email wizzer.cn@gmail.com
* @date 2019-03-06 21:45
*/
@IocBean
public class NacosConfigureLoader extends PropertiesConfigureLoader {
@IocBean(create = "init")
public class NacosConfigureLoader {
/**
* 获取日志对象
*/
@ -111,13 +98,16 @@ public class NacosConfigureLoader extends PropertiesConfigureLoader {
@Inject
protected AppContext appContext;
@Inject
private PropertiesProxy conf;
protected ConfigService configService;
private List<ConfigListener> configListenerList;
public void addConfigListener(ConfigListener configListener) {
if(null == configListenerList) {
if (null == configListenerList) {
configListenerList = new ArrayList<>();
}
configListenerList.add(configListener);
@ -127,6 +117,10 @@ public class NacosConfigureLoader extends PropertiesConfigureLoader {
if ("json".equals(contentType)) {
NutMap configMap = new NutMap(content);
conf.putAll(configMap);
} else if ("yaml".equals(contentType)) {
Map<String, Object> result = new HashMap<>();
buildFlattenedMap(result, new Yaml().loadAs(content, Map.class), "");
conf.putAll(result);
} else if ("xml".equals(contentType)) {
Properties properties = new Properties();
try {
@ -144,37 +138,69 @@ public class NacosConfigureLoader extends PropertiesConfigureLoader {
throw Lang.makeThrow("nacos.config.data_type is not found or not recognizeonly json,xml and properties are support!");
}
}
private void buildFlattenedMap(Map<String, Object> result, Map<String, Object> source, String path) {
for (Map.Entry<String, Object> entry : source.entrySet()) {
String key = Strings.sNull(entry.getKey());
if (Strings.isNotBlank(path)) {
if (key.startsWith("[")) {
key = path + key;
} else {
key = path + "." + key;
}
}
Object value = entry.getValue();
if (value instanceof Map) {
@SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String, Object>) value;
buildFlattenedMap(result, map, key);
} else if (value instanceof Collection) {
@SuppressWarnings("unchecked")
Collection<Object> collection = (Collection<Object>) value;
StringBuilder val = new StringBuilder();
for (Object object : collection) {
String str = Strings.sNull(object);
if (str.startsWith("{") && str.endsWith("}")) {
val.append(Json.toJson(object, JsonFormat.compact())).append("\n");
} else {
val.append(str).append("\n");
}
}
result.put(key, val.toString());
} else {
result.put(key, Strings.sNull(value));
}
}
}
protected String dataId;
protected String group;
@Override
public void init() throws Exception {
super.init();
dataId = conf.get(NACOS_DATA_ID, conf.get("nutz.application.name", "nutzboot"));
group = conf.get(NACOS_GROUP, "DEFAULT_GROUP");
configService = NacosFactory.createConfigService(getNacosConfigProperties());
String configInfo = configService.getConfigAndSignListener(dataId, group, 5000, new com.alibaba.nacos.api.config.listener.Listener() {
public Executor getExecutor() {
return null;
}
public Executor getExecutor() {
return null;
}
@Override
public void receiveConfigInfo(String configInfo) {
updateConfigString(configInfo);
if(null != configListenerList) {
@Override
public void receiveConfigInfo(String configInfo) {
updateConfigString(configInfo);
if (null != configListenerList) {
for (ConfigListener configListener : configListenerList) {
configListener.reloadConfig();
}
}
}
}
});
updateConfigString(configInfo);
}
protected void updateConfigString(String configInfo) {
log.debugf("get nacos config%s", configInfo);
log.debugf("get nacos config%s", configInfo);
String dataType = conf.get(NACOS_DATA_TYPE, "properties");
if (Strings.isNotBlank(configInfo)) {
setConfig(configInfo, dataType, conf);
@ -204,17 +230,17 @@ public class NacosConfigureLoader extends PropertiesConfigureLoader {
}
return properties;
}
@IocBean(name="nacosConfigService")
@IocBean(name = "nacosConfigService")
public ConfigService getConfigService() {
return configService;
return configService;
}
public String getDataId() {
return dataId;
}
return dataId;
}
public String getGroup() {
return group;
}
return group;
}
}

View File

@ -1,28 +1,27 @@
package org.nutz.boot.starter.nutz.mvc;
import java.util.Set;
import org.nutz.boot.AppContext;
import org.nutz.boot.starter.nutz.mvc.api.ActionLoaderFace;
import org.nutz.ioc.Ioc;
import org.nutz.lang.Stopwatch;
import org.nutz.lang.Strings;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.EntryDeterminer;
import org.nutz.mvc.LoadingException;
import org.nutz.mvc.Mvcs;
import org.nutz.mvc.NutConfig;
import org.nutz.mvc.Setup;
import org.nutz.mvc.UrlMapping;
import org.nutz.mvc.*;
import org.nutz.mvc.annotation.ChainBy;
import org.nutz.mvc.annotation.Localization;
import org.nutz.mvc.impl.Loadings;
import org.nutz.mvc.impl.NutActionChainMaker;
import org.nutz.mvc.impl.NutLoading;
import java.util.Set;
public class NbMvcLoading extends NutLoading {
private static final Log log = Logs.get();
protected AppContext appContext = AppContext.getDefault();
public UrlMapping load(NutConfig config) {
config.setMainModule(appContext.getMainClass());
return super.load(config);
@ -49,6 +48,21 @@ public class NbMvcLoading extends NutLoading {
return modules;
}
protected ActionChainMaker createChainMaker(NutConfig config, Class<?> mainModule) {
ActionChainMaker maker;
String chain = config.getInitParameter("chain");
if (Strings.isNotBlank(chain)) {
maker = new NutActionChainMaker(chain);
} else {
ChainBy ann = mainModule.getAnnotation(ChainBy.class);
maker = null == ann ? new NutActionChainMaker(new String[]{})
: Loadings.evalObj(config, ann.type(), ann.args());
}
if (log.isDebugEnabled())
log.debugf("@ChainBy(%s)", maker.getClass().getName());
return maker;
}
public void depose(NutConfig config) {
if (log.isInfoEnabled())
log.infof("Nutz.Mvc[%s] is deposing ...", config.getAppName());
@ -59,8 +73,7 @@ public class NbMvcLoading extends NutLoading {
Setup setup = config.getAttributeAs(Setup.class, Setup.class.getName());
if (null != setup)
setup.destroy(config);
}
catch (Exception e) {
} catch (Exception e) {
throw new LoadingException(e);
}

View File

@ -30,7 +30,8 @@ public class NutFilterStarter implements WebFilterFace {
public static final String PROP_EXCLUSIONS = "nutz.mvc.exclusions";
@PropDoc(value="指定NutFilter执行顺序", defaultValue="")
public static final String PROP_WEB_FILTER_ORDER_NUTZ = "web.filter.order.nutz";
@PropDoc(value="指定Chain文件路径", defaultValue="")
public static final String PROP_WEB_FILTER_CHAIN = "web.filter.chain.path";
@Inject
protected PropertiesProxy conf;
@ -73,6 +74,7 @@ public class NutFilterStarter implements WebFilterFace {
}
}
params.put("exclusions", conf.get(PROP_EXCLUSIONS, "") + sb);
params.put("chain", conf.get(PROP_WEB_FILTER_CHAIN, ""));
return params;
}

13
pom.xml
View File

@ -14,7 +14,7 @@
<slf4j.version>1.7.30</slf4j.version>
<slf4j-api.version>1.7.30</slf4j-api.version>
<logback.version>1.2.3</logback.version>
<dubbo.version>2.6.7</dubbo.version>
<dubbo.version>2.6.9</dubbo.version>
<sentinel.version>1.7.2</sentinel.version>
<jetty.version>9.4.34.v20201102</jetty.version>
<tomcat.version>8.5.57</tomcat.version>
@ -29,7 +29,7 @@
<undertow.version>2.2.3.Final</undertow.version>
<velocity.version>1.7</velocity.version>
<caffeine.version>2.6.2</caffeine.version>
<feign.version>9.5.1</feign.version>
<feign.version>11.1</feign.version>
<hystrix.vesion>1.5.12</hystrix.vesion>
<web3j.vesion>3.2.0</web3j.vesion>
<mqtt.version>1.2.1</mqtt.version>
@ -49,8 +49,8 @@
<fescar.version>0.4.1</fescar.version>
<seata.version>1.2.0</seata.version>
<redisson.version>3.12.3</redisson.version>
<mybatis.version>3.5.2</mybatis.version>
<nacos.version>1.1.4</nacos.version>
<mybatis.version>3.5.6</mybatis.version>
<nacos.version>2.0.0</nacos.version>
<swagger-servlet.version>1.6.0</swagger-servlet.version>
<swagger3.version>2.1.1</swagger3.version>
<shardingsphere.version>4.1.0</shardingsphere.version>
@ -538,6 +538,11 @@
<artifactId>nutzboot-starter-feign</artifactId>
<version>${nutzboot.version}</version>
</dependency>
<dependency>
<groupId>org.nutz</groupId>
<artifactId>nutzboot-starter-ftp</artifactId>
<version>${nutzboot.version}</version>
</dependency>
<dependency>
<groupId>org.nutz</groupId>
<artifactId>nutzboot-starter-nutz-mvc</artifactId>