Compare commits
10 Commits
Author | SHA1 | Date |
---|---|---|
|
ce41f4d407 | |
|
bede11a7e2 | |
|
9388aa7f65 | |
|
4b106fb992 | |
|
9b61ef68d2 | |
|
0a75c0b8c0 | |
|
eb8b10f3f3 | |
|
b209b291c2 | |
|
fcf008405b | |
|
1ada9f4e88 |
|
@ -30,9 +30,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.nacos</groupId>
|
<groupId>com.alibaba.nacos</groupId>
|
||||||
<artifactId>nacos-spring-context</artifactId>
|
<artifactId>nacos-spring-context</artifactId>
|
||||||
<version>${revision}</version>
|
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -17,19 +17,15 @@
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<!-- java-->
|
<!-- java-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.annotation</groupId>
|
<groupId>javax.annotation</groupId>
|
||||||
<artifactId>javax.annotation-api</artifactId>
|
<artifactId>javax.annotation-api</artifactId>
|
||||||
<version>${javax.annotation-api.version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Nacos -->
|
<!-- Nacos -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.nacos</groupId>
|
<groupId>com.alibaba.nacos</groupId>
|
||||||
<artifactId>nacos-client</artifactId>
|
<artifactId>nacos-client</artifactId>
|
||||||
<version>${nacos.version}</version>
|
|
||||||
<exclusions>
|
<exclusions>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
<groupId>org.yaml</groupId>
|
<groupId>org.yaml</groupId>
|
||||||
|
@ -41,38 +37,30 @@
|
||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-core</artifactId>
|
<artifactId>jackson-core</artifactId>
|
||||||
<version>2.13.4</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!--yaml-->
|
<!--yaml-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.yaml</groupId>
|
<groupId>org.yaml</groupId>
|
||||||
<artifactId>snakeyaml</artifactId>
|
<artifactId>snakeyaml</artifactId>
|
||||||
<version>${snake.yaml.version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Spring Framework -->
|
<!-- Spring Framework -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-context</artifactId>
|
<artifactId>spring-context</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Spring Context Extras -->
|
<!-- Spring Context Extras -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.spring</groupId>
|
<groupId>com.alibaba.spring</groupId>
|
||||||
<artifactId>spring-context-support</artifactId>
|
<artifactId>spring-context-support</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Testing -->
|
<!-- Testing -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>${project.groupId}</groupId>
|
<groupId>${project.groupId}</groupId>
|
||||||
|
@ -80,30 +68,27 @@
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-test</artifactId>
|
<artifactId>spring-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ch.qos.logback</groupId>
|
<groupId>ch.qos.logback</groupId>
|
||||||
<artifactId>logback-classic</artifactId>
|
<artifactId>logback-classic</artifactId>
|
||||||
<version>1.2.9</version>
|
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mockito</groupId>
|
<groupId>org.mockito</groupId>
|
||||||
<artifactId>mockito-core</artifactId>
|
<artifactId>mockito-core</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.guava</groupId>
|
||||||
|
<artifactId>guava</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
</project>
|
||||||
</project>
|
|
|
@ -406,8 +406,10 @@ public abstract class AbstractAnnotationBeanPostProcessor implements Instantiati
|
||||||
|
|
||||||
if (injectedObject == null) {
|
if (injectedObject == null) {
|
||||||
injectedObject = doGetInjectedBean(attributes, bean, beanName, injectedType, injectedElement);
|
injectedObject = doGetInjectedBean(attributes, bean, beanName, injectedType, injectedElement);
|
||||||
// Customized inject-object if necessary
|
if (injectedObject != null) {
|
||||||
injectedObjectsCache.putIfAbsent(cacheKey, injectedObject);
|
// Customized inject-object if necessary
|
||||||
|
injectedObjectsCache.putIfAbsent(cacheKey, injectedObject);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return injectedObject;
|
return injectedObject;
|
||||||
|
@ -639,4 +641,4 @@ public abstract class AbstractAnnotationBeanPostProcessor implements Instantiati
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import com.alibaba.nacos.spring.beans.factory.annotation.AbstractAnnotationBeanPostProcessor;
|
import com.alibaba.nacos.spring.beans.factory.annotation.AbstractAnnotationBeanPostProcessor;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -181,7 +182,7 @@ public class NacosValueAnnotationBeanPostProcessor
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object resolveNotifyValue(String nacosValueExpr, String key, String newValue) {
|
private Object resolveNotifyValue(String nacosValueExpr, String key, String newValue) {
|
||||||
String spelExpr = nacosValueExpr.replaceAll("\\$\\{" + key + PLACEHOLDER_SUFFIX, newValue);
|
String spelExpr = StringUtils.replace(nacosValueExpr, PLACEHOLDER_PREFIX + key + PLACEHOLDER_SUFFIX, newValue);
|
||||||
return resolveStringValue(spelExpr);
|
return resolveStringValue(spelExpr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,331 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* 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 com.alibaba.nacos.spring.context.annotation.config;
|
||||||
|
|
||||||
|
import com.alibaba.nacos.common.utils.MD5Utils;
|
||||||
|
import com.alibaba.nacos.spring.beans.factory.annotation.AbstractAnnotationBeanPostProcessor;
|
||||||
|
import com.alibaba.nacos.spring.context.event.config.NacosConfigReceivedEvent;
|
||||||
|
import com.alibaba.nacos.spring.util.NacosUtils;
|
||||||
|
import com.alibaba.nacos.spring.util.PlaceholderHelper;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.beans.TypeConverter;
|
||||||
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
|
import org.springframework.beans.factory.BeanFactoryAware;
|
||||||
|
import org.springframework.beans.factory.annotation.InjectionMetadata;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.beans.factory.config.BeanExpressionContext;
|
||||||
|
import org.springframework.beans.factory.config.BeanExpressionResolver;
|
||||||
|
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||||
|
import org.springframework.context.ApplicationListener;
|
||||||
|
import org.springframework.context.EnvironmentAware;
|
||||||
|
import org.springframework.core.MethodParameter;
|
||||||
|
import org.springframework.core.annotation.AnnotationAttributes;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
import org.springframework.util.ReflectionUtils;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Member;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import static org.springframework.core.annotation.AnnotationUtils.getAnnotation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author wuhaoqiang
|
||||||
|
* @since 1.1.2
|
||||||
|
**/
|
||||||
|
public class SpringValueAnnotationBeanPostProcessor
|
||||||
|
extends AbstractAnnotationBeanPostProcessor implements BeanFactoryAware,
|
||||||
|
EnvironmentAware, ApplicationListener<NacosConfigReceivedEvent> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of {@link SpringValueAnnotationBeanPostProcessor} bean.
|
||||||
|
*/
|
||||||
|
public static final String BEAN_NAME = "StringValueAnnotationBeanPostProcessor";
|
||||||
|
|
||||||
|
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* placeholder, valueTarget.
|
||||||
|
*/
|
||||||
|
private Map<String, List<StringValueTarget>> placeholderStringValueTargetMap = new HashMap<String, List<StringValueTarget>>();
|
||||||
|
|
||||||
|
private ConfigurableListableBeanFactory beanFactory;
|
||||||
|
|
||||||
|
private Environment environment;
|
||||||
|
|
||||||
|
private BeanExpressionResolver exprResolver;
|
||||||
|
|
||||||
|
private BeanExpressionContext exprContext;
|
||||||
|
|
||||||
|
public SpringValueAnnotationBeanPostProcessor() {
|
||||||
|
super(Value.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
||||||
|
if (!(beanFactory instanceof ConfigurableListableBeanFactory)) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"StringValueAnnotationBeanPostProcessor requires a ConfigurableListableBeanFactory");
|
||||||
|
}
|
||||||
|
this.beanFactory = (ConfigurableListableBeanFactory) beanFactory;
|
||||||
|
this.exprResolver = ((ConfigurableListableBeanFactory) beanFactory).getBeanExpressionResolver();
|
||||||
|
this.exprContext = new BeanExpressionContext((ConfigurableListableBeanFactory) beanFactory, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setEnvironment(Environment environment) {
|
||||||
|
this.environment = environment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object doGetInjectedBean(AnnotationAttributes attributes, Object bean,
|
||||||
|
String beanName, Class<?> injectedType,
|
||||||
|
InjectionMetadata.InjectedElement injectedElement) throws Exception {
|
||||||
|
Object value = resolveStringValue(attributes.getString("value"));
|
||||||
|
Member member = injectedElement.getMember();
|
||||||
|
if (member instanceof Field) {
|
||||||
|
return convertIfNecessary((Field) member, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (member instanceof Method) {
|
||||||
|
return convertIfNecessary((Method) member, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String buildInjectedObjectCacheKey(AnnotationAttributes attributes,
|
||||||
|
Object bean, String beanName, Class<?> injectedType,
|
||||||
|
InjectionMetadata.InjectedElement injectedElement) {
|
||||||
|
return bean.getClass().getName() + attributes;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object postProcessBeforeInitialization(Object bean, final String beanName)
|
||||||
|
throws BeansException {
|
||||||
|
|
||||||
|
doWithFields(bean, beanName);
|
||||||
|
|
||||||
|
doWithMethods(bean, beanName);
|
||||||
|
|
||||||
|
return super.postProcessBeforeInitialization(bean, beanName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onApplicationEvent(NacosConfigReceivedEvent event) {
|
||||||
|
if (StringUtils.isEmpty(event)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Map<String, Object> updateProperties = NacosUtils.toProperties(event.getContent(), event.getType());
|
||||||
|
|
||||||
|
for (Map.Entry<String, List<StringValueTarget>> entry : placeholderStringValueTargetMap
|
||||||
|
.entrySet()) {
|
||||||
|
|
||||||
|
String key = environment.resolvePlaceholders(entry.getKey());
|
||||||
|
// Process modified keys, excluding deleted keys
|
||||||
|
if (!updateProperties.containsKey(key)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String newValue = environment.getProperty(key);
|
||||||
|
|
||||||
|
if (newValue == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
List<StringValueTarget> beanPropertyList = entry.getValue();
|
||||||
|
for (StringValueTarget target : beanPropertyList) {
|
||||||
|
String md5String = MD5Utils.md5Hex(newValue, "UTF-8");
|
||||||
|
boolean isUpdate = !target.lastMD5.equals(md5String);
|
||||||
|
if (isUpdate) {
|
||||||
|
target.updateLastMD5(md5String);
|
||||||
|
Object evaluatedValue = resolveStringValue(target.stringValueExpr);
|
||||||
|
if (target.method == null) {
|
||||||
|
setField(target, evaluatedValue);
|
||||||
|
} else {
|
||||||
|
setMethod(target, evaluatedValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object resolveStringValue(String strVal) {
|
||||||
|
String value = beanFactory.resolveEmbeddedValue(strVal);
|
||||||
|
if (exprResolver != null && value != null) {
|
||||||
|
return exprResolver.evaluate(value, exprContext);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object convertIfNecessary(Field field, Object value) {
|
||||||
|
TypeConverter converter = beanFactory.getTypeConverter();
|
||||||
|
return converter.convertIfNecessary(value, field.getType(), field);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object convertIfNecessary(Method method, Object value) {
|
||||||
|
Class<?>[] paramTypes = method.getParameterTypes();
|
||||||
|
Object[] arguments = new Object[paramTypes.length];
|
||||||
|
|
||||||
|
TypeConverter converter = beanFactory.getTypeConverter();
|
||||||
|
|
||||||
|
if (arguments.length == 1) {
|
||||||
|
return converter.convertIfNecessary(value, paramTypes[0],
|
||||||
|
new MethodParameter(method, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < arguments.length; i++) {
|
||||||
|
arguments[i] = converter.convertIfNecessary(value, paramTypes[i],
|
||||||
|
new MethodParameter(method, i));
|
||||||
|
}
|
||||||
|
|
||||||
|
return arguments;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doWithFields(final Object bean, final String beanName) {
|
||||||
|
ReflectionUtils.doWithFields(bean.getClass(),
|
||||||
|
new ReflectionUtils.FieldCallback() {
|
||||||
|
@Override
|
||||||
|
public void doWith(Field field) throws IllegalArgumentException {
|
||||||
|
Value annotation = getAnnotation(field, Value.class);
|
||||||
|
doWithAnnotation(beanName, bean, annotation, field.getModifiers(),
|
||||||
|
null, field);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doWithMethods(final Object bean, final String beanName) {
|
||||||
|
ReflectionUtils.doWithMethods(bean.getClass(),
|
||||||
|
new ReflectionUtils.MethodCallback() {
|
||||||
|
@Override
|
||||||
|
public void doWith(Method method) throws IllegalArgumentException {
|
||||||
|
Value annotation = getAnnotation(method, Value.class);
|
||||||
|
doWithAnnotation(beanName, bean, annotation,
|
||||||
|
method.getModifiers(), method, null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doWithAnnotation(String beanName, Object bean, Value annotation,
|
||||||
|
int modifiers, Method method, Field field) {
|
||||||
|
if (annotation != null) {
|
||||||
|
if (Modifier.isStatic(modifiers)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<String> placeholderList = PlaceholderHelper.findPlaceholderKeys(annotation.value());
|
||||||
|
for (String placeholder : placeholderList) {
|
||||||
|
StringValueTarget stringValueTarget = new StringValueTarget(bean, beanName,
|
||||||
|
method, field, annotation.value());
|
||||||
|
put2ListMap(placeholderStringValueTargetMap, placeholder,
|
||||||
|
stringValueTarget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private <K, V> void put2ListMap(Map<K, List<V>> map, K key, V value) {
|
||||||
|
List<V> valueList = map.get(key);
|
||||||
|
if (valueList == null) {
|
||||||
|
valueList = new ArrayList<V>();
|
||||||
|
}
|
||||||
|
valueList.add(value);
|
||||||
|
map.put(key, valueList);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setMethod(StringValueTarget stringValueTarget, Object propertyValue) {
|
||||||
|
Method method = stringValueTarget.method;
|
||||||
|
ReflectionUtils.makeAccessible(method);
|
||||||
|
try {
|
||||||
|
method.invoke(stringValueTarget.bean,
|
||||||
|
convertIfNecessary(method, propertyValue));
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("Update value with {} (method) in {} (bean) with {}",
|
||||||
|
method.getName(), stringValueTarget.beanName, propertyValue);
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
if (logger.isErrorEnabled()) {
|
||||||
|
logger.error("Can't update value with " + method.getName()
|
||||||
|
+ " (method) in " + stringValueTarget.beanName + " (bean)", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setField(final StringValueTarget stringValueTarget,
|
||||||
|
final Object propertyValue) {
|
||||||
|
final Object bean = stringValueTarget.bean;
|
||||||
|
|
||||||
|
Field field = stringValueTarget.field;
|
||||||
|
|
||||||
|
String fieldName = field.getName();
|
||||||
|
|
||||||
|
try {
|
||||||
|
ReflectionUtils.makeAccessible(field);
|
||||||
|
field.set(bean, convertIfNecessary(field, propertyValue));
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("Update value of the {}" + " (field) in {} (bean) with {}",
|
||||||
|
fieldName, stringValueTarget.beanName, propertyValue);
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
if (logger.isErrorEnabled()) {
|
||||||
|
logger.error("Can't update value of the " + fieldName + " (field) in "
|
||||||
|
+ stringValueTarget.beanName + " (bean)", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class StringValueTarget {
|
||||||
|
|
||||||
|
private final Object bean;
|
||||||
|
|
||||||
|
private final String beanName;
|
||||||
|
|
||||||
|
private final Method method;
|
||||||
|
|
||||||
|
private final Field field;
|
||||||
|
|
||||||
|
private String lastMD5;
|
||||||
|
|
||||||
|
private final String stringValueExpr;
|
||||||
|
|
||||||
|
StringValueTarget(Object bean, String beanName, Method method, Field field, String stringValueExpr) {
|
||||||
|
this.bean = bean;
|
||||||
|
|
||||||
|
this.beanName = beanName;
|
||||||
|
|
||||||
|
this.method = method;
|
||||||
|
|
||||||
|
this.field = field;
|
||||||
|
|
||||||
|
this.lastMD5 = "";
|
||||||
|
|
||||||
|
this.stringValueExpr = stringValueExpr;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void updateLastMD5(String newMD5) {
|
||||||
|
this.lastMD5 = newMD5;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -174,7 +174,7 @@ public class EventPublishingConfigService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy lifecycle method to invoke {@link #shutDown()}
|
* Destroy lifecycle method to invoke {@link #shutDown()}
|
||||||
* @throws Exception
|
* @throws Exception throw exception
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -87,7 +87,7 @@ public enum FileTypeEnum {
|
||||||
* Get the corresponding FileTypeEnum by file extension or fileType. If not found FileTypeEnum.TEXT is returned
|
* Get the corresponding FileTypeEnum by file extension or fileType. If not found FileTypeEnum.TEXT is returned
|
||||||
*
|
*
|
||||||
* @param extOrFileType file extension or fileType
|
* @param extOrFileType file extension or fileType
|
||||||
* @return
|
* @return return {@link FileTypeEnum}
|
||||||
*/
|
*/
|
||||||
public static FileTypeEnum getFileTypeEnumByFileExtensionOrFileType(String extOrFileType) {
|
public static FileTypeEnum getFileTypeEnumByFileExtensionOrFileType(String extOrFileType) {
|
||||||
if (StringUtils.isNotBlank(extOrFileType)) {
|
if (StringUtils.isNotBlank(extOrFileType)) {
|
||||||
|
|
|
@ -92,7 +92,8 @@ public final class ConfigParseUtils {
|
||||||
|
|
||||||
if (DEFAULT_CONFIG_PARSE_MAP.containsKey(type)) {
|
if (DEFAULT_CONFIG_PARSE_MAP.containsKey(type)) {
|
||||||
ConfigParse configParse = DEFAULT_CONFIG_PARSE_MAP.get(type);
|
ConfigParse configParse = DEFAULT_CONFIG_PARSE_MAP.get(type);
|
||||||
return configParse.parse(context);
|
Map<String, Object> parseMap = configParse.parse(context);
|
||||||
|
return parseMap == null ? new HashMap<>() : parseMap;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new UnsupportedOperationException(
|
throw new UnsupportedOperationException(
|
||||||
|
|
|
@ -29,6 +29,7 @@ import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ThreadFactory;
|
import java.util.concurrent.ThreadFactory;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
import com.alibaba.nacos.spring.context.annotation.config.SpringValueAnnotationBeanPostProcessor;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.springframework.beans.factory.BeanFactory;
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
import org.springframework.beans.factory.ListableBeanFactory;
|
import org.springframework.beans.factory.ListableBeanFactory;
|
||||||
|
@ -362,6 +363,13 @@ public abstract class NacosBeanUtils {
|
||||||
NacosValueAnnotationBeanPostProcessor.class);
|
NacosValueAnnotationBeanPostProcessor.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void registerStringValueAnnotationBeanPostProcessor(
|
||||||
|
BeanDefinitionRegistry registry) {
|
||||||
|
registerInfrastructureBeanIfAbsent(registry,
|
||||||
|
SpringValueAnnotationBeanPostProcessor.BEAN_NAME,
|
||||||
|
SpringValueAnnotationBeanPostProcessor.class);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register Nacos Common Beans
|
* Register Nacos Common Beans
|
||||||
*
|
*
|
||||||
|
@ -398,6 +406,8 @@ public abstract class NacosBeanUtils {
|
||||||
|
|
||||||
registerNacosValueAnnotationBeanPostProcessor(registry);
|
registerNacosValueAnnotationBeanPostProcessor(registry);
|
||||||
|
|
||||||
|
registerStringValueAnnotationBeanPostProcessor(registry);
|
||||||
|
|
||||||
registerConfigServiceBeanBuilder(registry);
|
registerConfigServiceBeanBuilder(registry);
|
||||||
|
|
||||||
registerLoggingNacosConfigMetadataEventListener(registry);
|
registerLoggingNacosConfigMetadataEventListener(registry);
|
||||||
|
|
|
@ -532,6 +532,7 @@ public abstract class NacosUtils {
|
||||||
* @param group config group
|
* @param group config group
|
||||||
* @param text config context
|
* @param text config context
|
||||||
* @param type config type
|
* @param type config type
|
||||||
|
* @return map format of result
|
||||||
*/
|
*/
|
||||||
public static Map<String, Object> toProperties(String dataId, String group,
|
public static Map<String, Object> toProperties(String dataId, String group,
|
||||||
String text, String type) {
|
String text, String type) {
|
||||||
|
|
|
@ -0,0 +1,126 @@
|
||||||
|
package com.alibaba.nacos.spring.util;
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.Stack;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author wuhaoqiang
|
||||||
|
* @since 1.1.2
|
||||||
|
**/
|
||||||
|
public class PlaceholderHelper {
|
||||||
|
|
||||||
|
private static final String PLACEHOLDER_PREFIX = "${";
|
||||||
|
private static final String PLACEHOLDER_SUFFIX = "}";
|
||||||
|
private static final String VALUE_SEPARATOR = ":";
|
||||||
|
private static final String SIMPLE_PLACEHOLDER_PREFIX = "{";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* find keys from placeholder
|
||||||
|
* ${key} - "key"
|
||||||
|
* xxx${key}yyy - "key"
|
||||||
|
* ${key:${key2:1}} - "key", "key2"
|
||||||
|
* ${${key}} - "key"
|
||||||
|
* ${${key:100}} - "key"
|
||||||
|
* ${${key}:${key2}} - "key", "key2"
|
||||||
|
* @param propertyString ${key}
|
||||||
|
* @return key
|
||||||
|
*/
|
||||||
|
public static Set<String> findPlaceholderKeys(String propertyString) {
|
||||||
|
Set<String> placeholderKeys = Sets.newHashSet();
|
||||||
|
|
||||||
|
if (Strings.isNullOrEmpty(propertyString) ||
|
||||||
|
!(propertyString.contains(PLACEHOLDER_PREFIX) && propertyString.contains(PLACEHOLDER_SUFFIX))) {
|
||||||
|
return placeholderKeys;
|
||||||
|
}
|
||||||
|
// handle xxx${yyy}zzz -> ${yyy}zzz
|
||||||
|
propertyString = propertyString.substring(propertyString.indexOf(PLACEHOLDER_PREFIX));
|
||||||
|
|
||||||
|
Stack<String> stack = new Stack<String>();
|
||||||
|
stack.push(propertyString);
|
||||||
|
|
||||||
|
while (!stack.isEmpty()) {
|
||||||
|
String strVal = stack.pop();
|
||||||
|
int startIndex = strVal.indexOf(PLACEHOLDER_PREFIX);
|
||||||
|
if (startIndex == -1) {
|
||||||
|
placeholderKeys.add(strVal);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int endIndex = findPlaceholderEndIndex(strVal, startIndex);
|
||||||
|
if (endIndex == -1) {
|
||||||
|
// invalid placeholder
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String placeholderCandidate = strVal.substring(startIndex + PLACEHOLDER_PREFIX.length(), endIndex);
|
||||||
|
|
||||||
|
// ${key}
|
||||||
|
// startsWith '${' continue
|
||||||
|
if (placeholderCandidate.startsWith(PLACEHOLDER_PREFIX)) {
|
||||||
|
stack.push(placeholderCandidate);
|
||||||
|
} else {
|
||||||
|
// exist ':' -> key:${key2:2}
|
||||||
|
int separatorIndex = placeholderCandidate.indexOf(VALUE_SEPARATOR);
|
||||||
|
|
||||||
|
if (separatorIndex == -1) {
|
||||||
|
stack.push(placeholderCandidate);
|
||||||
|
} else {
|
||||||
|
stack.push(placeholderCandidate.substring(0, separatorIndex));
|
||||||
|
String defaultValuePart =
|
||||||
|
normalizeToPlaceholder(placeholderCandidate.substring(separatorIndex + VALUE_SEPARATOR.length()));
|
||||||
|
if (!Strings.isNullOrEmpty(defaultValuePart)) {
|
||||||
|
stack.push(defaultValuePart);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// has remaining part, e.g. ${a}.${b}
|
||||||
|
if (endIndex + PLACEHOLDER_SUFFIX.length() < strVal.length() - 1) {
|
||||||
|
String remainingPart = normalizeToPlaceholder(strVal.substring(endIndex + PLACEHOLDER_SUFFIX.length()));
|
||||||
|
if (!Strings.isNullOrEmpty(remainingPart)) {
|
||||||
|
stack.push(remainingPart);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return placeholderKeys;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String normalizeToPlaceholder(String strVal) {
|
||||||
|
int startIndex = strVal.indexOf(PLACEHOLDER_PREFIX);
|
||||||
|
if (startIndex == -1) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
int endIndex = strVal.lastIndexOf(PLACEHOLDER_SUFFIX);
|
||||||
|
if (endIndex == -1) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return strVal.substring(startIndex, endIndex + PLACEHOLDER_SUFFIX.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int findPlaceholderEndIndex(CharSequence buf, int startIndex) {
|
||||||
|
int index = startIndex + PLACEHOLDER_PREFIX.length();
|
||||||
|
int withinNestedPlaceholder = 0;
|
||||||
|
while (index < buf.length()) {
|
||||||
|
if (StringUtils.substringMatch(buf, index, PLACEHOLDER_SUFFIX)) {
|
||||||
|
if (withinNestedPlaceholder > 0) {
|
||||||
|
withinNestedPlaceholder--;
|
||||||
|
index = index + PLACEHOLDER_SUFFIX.length();
|
||||||
|
} else {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
} else if (StringUtils.substringMatch(buf, index, SIMPLE_PLACEHOLDER_PREFIX)) {
|
||||||
|
withinNestedPlaceholder++;
|
||||||
|
index = index + SIMPLE_PLACEHOLDER_PREFIX.length();
|
||||||
|
} else {
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ public abstract class NativeDetector {
|
||||||
private static final boolean imageCode = (System.getProperty("org.graalvm.nativeimage.imagecode") != null);
|
private static final boolean imageCode = (System.getProperty("org.graalvm.nativeimage.imagecode") != null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns {@code true} if invoked in the context of image building or during image runtime, else {@code false}.
|
* @return Returns {@code true} if invoked in the context of image building or during image runtime, else {@code false}.
|
||||||
*/
|
*/
|
||||||
public static boolean inNativeImage() {
|
public static boolean inNativeImage() {
|
||||||
return imageCode;
|
return imageCode;
|
||||||
|
|
|
@ -27,18 +27,14 @@ import org.yaml.snakeyaml.LoaderOptions;
|
||||||
import org.yaml.snakeyaml.Yaml;
|
import org.yaml.snakeyaml.Yaml;
|
||||||
import org.yaml.snakeyaml.constructor.Constructor;
|
import org.yaml.snakeyaml.constructor.Constructor;
|
||||||
import org.yaml.snakeyaml.constructor.SafeConstructor;
|
import org.yaml.snakeyaml.constructor.SafeConstructor;
|
||||||
import org.yaml.snakeyaml.nodes.MappingNode;
|
|
||||||
import org.yaml.snakeyaml.nodes.Tag;
|
import org.yaml.snakeyaml.nodes.Tag;
|
||||||
import org.yaml.snakeyaml.parser.ParserException;
|
|
||||||
import org.yaml.snakeyaml.representer.Representer;
|
import org.yaml.snakeyaml.representer.Representer;
|
||||||
import org.yaml.snakeyaml.resolver.Resolver;
|
import org.yaml.snakeyaml.resolver.Resolver;
|
||||||
|
|
||||||
import java.util.AbstractMap;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@ -49,30 +45,30 @@ import java.util.regex.Pattern;
|
||||||
* @since 0.3.0
|
* @since 0.3.0
|
||||||
*/
|
*/
|
||||||
public class DefaultYamlConfigParse extends AbstractConfigParse {
|
public class DefaultYamlConfigParse extends AbstractConfigParse {
|
||||||
|
|
||||||
protected static final Logger LOGGER = LoggerFactory.getLogger(DefaultYamlConfigParse.class);
|
protected static final Logger LOGGER = LoggerFactory.getLogger(DefaultYamlConfigParse.class);
|
||||||
|
|
||||||
private static final String YAML_ALLOW_COMPLEX_OBJECT = "yamlAllowComplexObject";
|
private static final String YAML_ALLOW_COMPLEX_OBJECT = "yamlAllowComplexObject";
|
||||||
|
|
||||||
private static boolean getYamlAllowComplexObject() {
|
private static boolean getYamlAllowComplexObject() {
|
||||||
return Boolean.getBoolean(YAML_ALLOW_COMPLEX_OBJECT);
|
return Boolean.getBoolean(YAML_ALLOW_COMPLEX_OBJECT);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static Yaml createYaml() {
|
protected static Yaml createYaml() {
|
||||||
SafeConstructor constructor;
|
|
||||||
if (getYamlAllowComplexObject()) {
|
|
||||||
constructor = new Constructor();
|
|
||||||
} else {
|
|
||||||
constructor = new SafeConstructor();
|
|
||||||
}
|
|
||||||
Representer representer = new Representer();
|
|
||||||
DumperOptions dumperOptions = new DumperOptions();
|
|
||||||
LimitedResolver resolver = new LimitedResolver();
|
|
||||||
LoaderOptions loaderOptions = new LoaderOptions();
|
LoaderOptions loaderOptions = new LoaderOptions();
|
||||||
loaderOptions.setAllowDuplicateKeys(false);
|
loaderOptions.setAllowDuplicateKeys(false);
|
||||||
|
SafeConstructor constructor;
|
||||||
|
if (getYamlAllowComplexObject()) {
|
||||||
|
constructor = new Constructor(loaderOptions);
|
||||||
|
} else {
|
||||||
|
constructor = new SafeConstructor(loaderOptions);
|
||||||
|
}
|
||||||
|
DumperOptions dumperOptions = new DumperOptions();
|
||||||
|
Representer representer = new Representer(dumperOptions);
|
||||||
|
LimitedResolver resolver = new LimitedResolver();
|
||||||
return new Yaml(constructor, representer, dumperOptions, loaderOptions, resolver);
|
return new Yaml(constructor, representer, dumperOptions, loaderOptions, resolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static boolean process(MatchCallback callback, Yaml yaml, String content) {
|
protected static boolean process(MatchCallback callback, Yaml yaml, String content) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
if (LOGGER.isDebugEnabled()) {
|
if (LOGGER.isDebugEnabled()) {
|
||||||
|
@ -88,7 +84,7 @@ public class DefaultYamlConfigParse extends AbstractConfigParse {
|
||||||
}
|
}
|
||||||
return (count > 0);
|
return (count > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static boolean process(Map<String, Object> map, MatchCallback callback) {
|
protected static boolean process(Map<String, Object> map, MatchCallback callback) {
|
||||||
if (LOGGER.isDebugEnabled()) {
|
if (LOGGER.isDebugEnabled()) {
|
||||||
LOGGER.debug("Merging document (no matchers set): " + map);
|
LOGGER.debug("Merging document (no matchers set): " + map);
|
||||||
|
@ -96,7 +92,7 @@ public class DefaultYamlConfigParse extends AbstractConfigParse {
|
||||||
callback.process(getFlattenedMap(map));
|
callback.process(getFlattenedMap(map));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
protected static Map<String, Object> asMap(Object object) {
|
protected static Map<String, Object> asMap(Object object) {
|
||||||
// YAML can have numbers as keys
|
// YAML can have numbers as keys
|
||||||
|
@ -106,7 +102,7 @@ public class DefaultYamlConfigParse extends AbstractConfigParse {
|
||||||
result.put("document", object);
|
result.put("document", object);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<Object, Object> map = (Map<Object, Object>) object;
|
Map<Object, Object> map = (Map<Object, Object>) object;
|
||||||
for (Map.Entry<Object, Object> entry : map.entrySet()) {
|
for (Map.Entry<Object, Object> entry : map.entrySet()) {
|
||||||
Object key = entry.getKey();
|
Object key = entry.getKey();
|
||||||
|
@ -122,9 +118,9 @@ public class DefaultYamlConfigParse extends AbstractConfigParse {
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class LimitedResolver extends Resolver {
|
private static class LimitedResolver extends Resolver {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addImplicitResolver(Tag tag, Pattern regexp, String first) {
|
public void addImplicitResolver(Tag tag, Pattern regexp, String first) {
|
||||||
if (tag == Tag.TIMESTAMP) {
|
if (tag == Tag.TIMESTAMP) {
|
||||||
|
@ -133,13 +129,13 @@ public class DefaultYamlConfigParse extends AbstractConfigParse {
|
||||||
super.addImplicitResolver(tag, regexp, first);
|
super.addImplicitResolver(tag, regexp, first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static Map<String, Object> getFlattenedMap(Map<String, Object> source) {
|
protected static Map<String, Object> getFlattenedMap(Map<String, Object> source) {
|
||||||
Map<String, Object> result = new LinkedHashMap<String, Object>();
|
Map<String, Object> result = new LinkedHashMap<String, Object>();
|
||||||
buildFlattenedMap(result, source, null);
|
buildFlattenedMap(result, source, null);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void buildFlattenedMap(Map<String, Object> result, Map<String, Object> source, String path) {
|
protected static void buildFlattenedMap(Map<String, Object> result, Map<String, Object> source, String path) {
|
||||||
for (Map.Entry<String, Object> entry : source.entrySet()) {
|
for (Map.Entry<String, Object> entry : source.entrySet()) {
|
||||||
String key = entry.getKey();
|
String key = entry.getKey();
|
||||||
|
@ -169,7 +165,7 @@ public class DefaultYamlConfigParse extends AbstractConfigParse {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> parse(String configText) {
|
public Map<String, Object> parse(String configText) {
|
||||||
final AtomicReference<Map<String, Object>> result = new AtomicReference<Map<String, Object>>();
|
final AtomicReference<Map<String, Object>> result = new AtomicReference<Map<String, Object>>();
|
||||||
|
@ -181,14 +177,14 @@ public class DefaultYamlConfigParse extends AbstractConfigParse {
|
||||||
}, createYaml(), configText);
|
}, createYaml(), configText);
|
||||||
return result.get();
|
return result.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String processType() {
|
public String processType() {
|
||||||
return ConfigType.YAML.getType();
|
return ConfigType.YAML.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected interface MatchCallback {
|
protected interface MatchCallback {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put Map to Properties.
|
* Put Map to Properties.
|
||||||
*
|
*
|
||||||
|
@ -196,5 +192,5 @@ public class DefaultYamlConfigParse extends AbstractConfigParse {
|
||||||
*/
|
*/
|
||||||
void process(Map<String, Object> map);
|
void process(Map<String, Object> map);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
package com.alibaba.nacos.spring.util;
|
||||||
|
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author whq
|
||||||
|
* @since 1.1.2
|
||||||
|
*/
|
||||||
|
public class PlaceholderHelperTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFindPlaceholderKeys() {
|
||||||
|
/**
|
||||||
|
* find keys from placeholder
|
||||||
|
* ${key} => "key"
|
||||||
|
* xxx${key}yyy => "key"
|
||||||
|
* ${key:${key2:1}} => "key", "key2"
|
||||||
|
* ${${key}} => "key"
|
||||||
|
* ${${key:100}} => "key"
|
||||||
|
* ${${key}:${key2}} => "key", "key2"
|
||||||
|
*/
|
||||||
|
Assert.assertEquals(PlaceholderHelper.findPlaceholderKeys("${key}"), Sets.newHashSet("key"));
|
||||||
|
Assert.assertEquals(PlaceholderHelper.findPlaceholderKeys("xxx${key}yyy"), Sets.newHashSet("key"));
|
||||||
|
Assert.assertEquals(PlaceholderHelper.findPlaceholderKeys("${key:${key2:1}}"), Sets.newHashSet("key", "key2"));
|
||||||
|
Assert.assertEquals(PlaceholderHelper.findPlaceholderKeys("${${key}}"), Sets.newHashSet("key"));
|
||||||
|
Assert.assertEquals(PlaceholderHelper.findPlaceholderKeys("${${key:100}}"), Sets.newHashSet("key"));
|
||||||
|
Assert.assertEquals(PlaceholderHelper.findPlaceholderKeys("${${key}:${key2}}"), Sets.newHashSet("key", "key2"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -15,34 +15,25 @@
|
||||||
<name>Alibaba Nacos :: Samples :: Embedded Web Server</name>
|
<name>Alibaba Nacos :: Samples :: Embedded Web Server</name>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.servlet</groupId>
|
<groupId>javax.servlet</groupId>
|
||||||
<artifactId>javax.servlet-api</artifactId>
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.annotation</groupId>
|
<groupId>javax.annotation</groupId>
|
||||||
<artifactId>javax.annotation-api</artifactId>
|
<artifactId>javax.annotation-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.nacos</groupId>
|
<groupId>com.alibaba.nacos</groupId>
|
||||||
<artifactId>nacos-client</artifactId>
|
<artifactId>nacos-client</artifactId>
|
||||||
<version>${nacos.version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
<version>${slf4j.version}</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-core</artifactId>
|
<artifactId>spring-core</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
|
@ -16,45 +16,34 @@
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.servlet</groupId>
|
<groupId>javax.servlet</groupId>
|
||||||
<artifactId>javax.servlet-api</artifactId>
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.annotation</groupId>
|
<groupId>javax.annotation</groupId>
|
||||||
<artifactId>javax.annotation-api</artifactId>
|
<artifactId>javax.annotation-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-core</artifactId>
|
<artifactId>spring-core</artifactId>
|
||||||
<version>4.0.5.RELEASE</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-context</artifactId>
|
<artifactId>spring-context</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-webmvc</artifactId>
|
<artifactId>spring-webmvc</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>${project.groupId}</groupId>
|
<groupId>${project.groupId}</groupId>
|
||||||
<artifactId>nacos-spring-context</artifactId>
|
<artifactId>nacos-spring-context</artifactId>
|
||||||
<version>${project.version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>${project.groupId}</groupId>
|
<groupId>${project.groupId}</groupId>
|
||||||
<artifactId>nacos-embedded-webserver</artifactId>
|
<artifactId>nacos-embedded-webserver</artifactId>
|
||||||
<version>${project.version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -20,20 +20,6 @@
|
||||||
<module>nacos-spring-webmvc-sample</module>
|
<module>nacos-spring-webmvc-sample</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<dependencyManagement>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-webmvc</artifactId>
|
|
||||||
<version>${spring.framework.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</dependencyManagement>
|
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
@ -46,6 +32,4 @@
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
77
pom.xml
77
pom.xml
|
@ -51,14 +51,12 @@
|
||||||
</mailingLists>
|
</mailingLists>
|
||||||
|
|
||||||
<developers>
|
<developers>
|
||||||
|
|
||||||
<developer>
|
<developer>
|
||||||
<id>Alibaba Nacos</id>
|
<id>Alibaba Nacos</id>
|
||||||
<name>Nacos</name>
|
<name>Nacos</name>
|
||||||
<url>http://nacos.io</url>
|
<url>http://nacos.io</url>
|
||||||
<email>nacos_dev@linux.alibaba.com</email>
|
<email>nacos_dev@linux.alibaba.com</email>
|
||||||
</developer>
|
</developer>
|
||||||
|
|
||||||
<developer>
|
<developer>
|
||||||
<id>mercyblitz</id>
|
<id>mercyblitz</id>
|
||||||
<name>小马哥</name>
|
<name>小马哥</name>
|
||||||
|
@ -76,7 +74,7 @@
|
||||||
</licenses>
|
</licenses>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<revision>2.1.0-RC</revision>
|
<revision>2.1.1</revision>
|
||||||
<argLine>-Dfile.encoding=UTF-8</argLine>
|
<argLine>-Dfile.encoding=UTF-8</argLine>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
|
@ -93,8 +91,10 @@
|
||||||
<nacos.version>2.2.1</nacos.version>
|
<nacos.version>2.2.1</nacos.version>
|
||||||
<!-- Spring -->
|
<!-- Spring -->
|
||||||
<spring.framework.version>5.2.9.RELEASE</spring.framework.version>
|
<spring.framework.version>5.2.9.RELEASE</spring.framework.version>
|
||||||
|
<logback-classic.version>1.2.9</logback-classic.version>
|
||||||
|
<guava.version>32.0.0-jre</guava.version>
|
||||||
<spring6.framework.version>6.0.8</spring6.framework.version>
|
<spring6.framework.version>6.0.8</spring6.framework.version>
|
||||||
<snake.yaml.version>1.29</snake.yaml.version>
|
<snakeyaml.version>1.29</snakeyaml.version>
|
||||||
<!-- Servlet -->
|
<!-- Servlet -->
|
||||||
<servlet-api.version>3.0.1</servlet-api.version>
|
<servlet-api.version>3.0.1</servlet-api.version>
|
||||||
<!-- javax-->
|
<!-- javax-->
|
||||||
|
@ -103,82 +103,118 @@
|
||||||
<commons-lang3.version>3.4</commons-lang3.version>
|
<commons-lang3.version>3.4</commons-lang3.version>
|
||||||
<!-- Alibaba's Spring Context Support -->
|
<!-- Alibaba's Spring Context Support -->
|
||||||
<spring-context-support.version>1.0.11</spring-context-support.version>
|
<spring-context-support.version>1.0.11</spring-context-support.version>
|
||||||
|
<jackson-core.version>2.13.4</jackson-core.version>
|
||||||
<slf4j.version>1.7.7</slf4j.version>
|
<slf4j.version>1.7.7</slf4j.version>
|
||||||
|
<junit.version>4.12</junit.version>
|
||||||
|
<mockito-core.version>2.15.0</mockito-core.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<!-- 管理依赖版本号,子项目不会默认依赖 -->
|
<!-- 管理依赖版本号,子项目不会默认依赖 -->
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.servlet</groupId>
|
<groupId>javax.servlet</groupId>
|
||||||
<artifactId>javax.servlet-api</artifactId>
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
<version>${servlet-api.version}</version>
|
<version>${servlet-api.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
<version>${slf4j.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.nacos</groupId>
|
<groupId>com.alibaba.nacos</groupId>
|
||||||
<artifactId>nacos-client</artifactId>
|
<artifactId>nacos-client</artifactId>
|
||||||
<version>${nacos.version}</version>
|
<version>${nacos.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Alibaba's Spring Context Support -->
|
<!-- Alibaba's Spring Context Support -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.spring</groupId>
|
<groupId>com.alibaba.spring</groupId>
|
||||||
<artifactId>spring-context-support</artifactId>
|
<artifactId>spring-context-support</artifactId>
|
||||||
<version>${spring-context-support.version}</version>
|
<version>${spring-context-support.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.annotation</groupId>
|
<groupId>javax.annotation</groupId>
|
||||||
<artifactId>javax.annotation-api</artifactId>
|
<artifactId>javax.annotation-api</artifactId>
|
||||||
<version>${javax.annotation-api.version}</version>
|
<version>${javax.annotation-api.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-core</artifactId>
|
||||||
|
<version>${jackson-core.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<!--yaml-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.yaml</groupId>
|
||||||
|
<artifactId>snakeyaml</artifactId>
|
||||||
|
<version>${snakeyaml.version}</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
<version>${commons-lang3.version}</version>
|
<version>${commons-lang3.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Spring Framework -->
|
<!-- Spring Framework -->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-core</artifactId>
|
<artifactId>spring-core</artifactId>
|
||||||
<version>${spring.framework.version}</version>
|
<version>${spring.framework.version}</version>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-context</artifactId>
|
<artifactId>spring-context</artifactId>
|
||||||
<version>${spring.framework.version}</version>
|
<version>${spring.framework.version}</version>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Testing -->
|
<!-- Testing -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>4.12</version>
|
<version>${junit.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-test</artifactId>
|
<artifactId>spring-test</artifactId>
|
||||||
<version>${spring.framework.version}</version>
|
<version>${spring.framework.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mockito</groupId>
|
<groupId>org.mockito</groupId>
|
||||||
<artifactId>mockito-core</artifactId>
|
<artifactId>mockito-core</artifactId>
|
||||||
<version>2.15.0</version>
|
<version>${mockito-core.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-webmvc</artifactId>
|
||||||
|
<version>${spring.framework.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ch.qos.logback</groupId>
|
||||||
|
<artifactId>logback-classic</artifactId>
|
||||||
|
<version>${logback-classic.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.guava</groupId>
|
||||||
|
<artifactId>guava</artifactId>
|
||||||
|
<version>${guava.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>nacos-spring-context</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>nacos-embedded-webserver</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
@ -282,7 +318,7 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
<artifactId>flatten-maven-plugin</artifactId>
|
<artifactId>flatten-maven-plugin</artifactId>
|
||||||
<version>1.1.0</version>
|
<version>1.6.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<updatePomFile>true</updatePomFile>
|
<updatePomFile>true</updatePomFile>
|
||||||
<flattenMode>resolveCiFriendliesOnly</flattenMode>
|
<flattenMode>resolveCiFriendliesOnly</flattenMode>
|
||||||
|
@ -362,6 +398,11 @@
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-war-plugin</artifactId>
|
||||||
|
<version>3.4.0</version>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue