mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
commit
0819960020
10
pom.xml
10
pom.xml
@ -55,6 +55,13 @@
|
|||||||
<name>hengyunabc</name>
|
<name>hengyunabc</name>
|
||||||
<email>hengyunabc@gmail.com</email>
|
<email>hengyunabc@gmail.com</email>
|
||||||
</developer>
|
</developer>
|
||||||
|
<developer>
|
||||||
|
<id>mercyblitz</id>
|
||||||
|
<name>Mercy Ma</name>
|
||||||
|
<email>mercyblitz@gmail.com</email>
|
||||||
|
<organization>Alibaba</organization>
|
||||||
|
<url>https://github.com/mercyblitz</url>
|
||||||
|
</developer>
|
||||||
</developers>
|
</developers>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
@ -81,13 +88,14 @@
|
|||||||
<module>spring-cloud-alibaba-sentinel-datasource</module>
|
<module>spring-cloud-alibaba-sentinel-datasource</module>
|
||||||
<module>spring-cloud-alibaba-nacos-config</module>
|
<module>spring-cloud-alibaba-nacos-config</module>
|
||||||
<module>spring-cloud-alibaba-nacos-discovery</module>
|
<module>spring-cloud-alibaba-nacos-discovery</module>
|
||||||
|
<module>spring-cloud-alibaba-nacos-config-server</module>
|
||||||
|
<module>spring-cloud-alicloud-context</module>
|
||||||
<module>spring-cloud-alibaba-examples</module>
|
<module>spring-cloud-alibaba-examples</module>
|
||||||
<module>spring-cloud-alibaba-test</module>
|
<module>spring-cloud-alibaba-test</module>
|
||||||
<module>spring-cloud-alibaba-docs</module>
|
<module>spring-cloud-alibaba-docs</module>
|
||||||
<module>spring-cloud-starter-alibaba</module>
|
<module>spring-cloud-starter-alibaba</module>
|
||||||
<module>spring-cloud-starter-alicloud</module>
|
<module>spring-cloud-starter-alicloud</module>
|
||||||
<module>spring-cloud-alicloud-oss</module>
|
<module>spring-cloud-alicloud-oss</module>
|
||||||
<module>spring-cloud-alicloud-context</module>
|
|
||||||
<module>spring-cloud-alicloud-acm</module>
|
<module>spring-cloud-alicloud-acm</module>
|
||||||
<module>spring-cloud-alicloud-ans</module>
|
<module>spring-cloud-alicloud-ans</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<!-- Alibaba -->
|
<!-- Alibaba -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
@ -60,11 +61,20 @@
|
|||||||
<artifactId>acm-sdk</artifactId>
|
<artifactId>acm-sdk</artifactId>
|
||||||
<version>${acm.version}</version>
|
<version>${acm.version}</version>
|
||||||
</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>
|
<version>${nacos.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.nacos</groupId>
|
||||||
|
<artifactId>nacos-config</artifactId>
|
||||||
|
<version>${nacos.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Sentinel -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.csp</groupId>
|
<groupId>com.alibaba.csp</groupId>
|
||||||
<artifactId>sentinel-core</artifactId>
|
<artifactId>sentinel-core</artifactId>
|
||||||
|
64
spring-cloud-alibaba-nacos-config-server/pom.xml
Normal file
64
spring-cloud-alibaba-nacos-config-server/pom.xml
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-alibaba</artifactId>
|
||||||
|
<version>0.2.1.BUILD-SNAPSHOT</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-alibaba-nacos-config-server</artifactId>
|
||||||
|
<name>Spring Cloud Alibaba Nacos Config Server</name>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<!-- Nacos Config -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.nacos</groupId>
|
||||||
|
<artifactId>nacos-config</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Spring Cloud -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-config-server</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Spring Boot -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-test-support</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.springframework.cloud.alibaba.nacos.config.server;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
|
import org.springframework.cloud.alibaba.nacos.config.server.environment.NacosEnvironmentRepository;
|
||||||
|
import org.springframework.cloud.config.server.EnableConfigServer;
|
||||||
|
import org.springframework.cloud.config.server.config.ConfigServerAutoConfiguration;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nacos Config Server Auto-Configuration
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||||
|
* @since 0.2.0
|
||||||
|
*/
|
||||||
|
@ConditionalOnClass(EnableConfigServer.class) // If class of @EnableConfigServer is present in class-path
|
||||||
|
@ComponentScan(basePackages = {
|
||||||
|
"com.alibaba.nacos.config.server",
|
||||||
|
})
|
||||||
|
@AutoConfigureBefore(ConfigServerAutoConfiguration.class)
|
||||||
|
@Configuration
|
||||||
|
public class NacosConfigServerAutoConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public NacosEnvironmentRepository nacosEnvironmentRepository() {
|
||||||
|
return new NacosEnvironmentRepository();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.springframework.cloud.alibaba.nacos.config.server.environment;
|
||||||
|
|
||||||
|
import com.alibaba.nacos.config.server.model.ConfigInfo;
|
||||||
|
import com.alibaba.nacos.config.server.service.PersistService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.cloud.config.environment.Environment;
|
||||||
|
import org.springframework.cloud.config.environment.PropertySource;
|
||||||
|
import org.springframework.cloud.config.server.environment.EnvironmentRepository;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.StringReader;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import static com.alibaba.nacos.config.server.constant.Constants.DEFAULT_GROUP;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nacos {@link EnvironmentRepository}
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||||
|
* @since 0.2.0
|
||||||
|
*/
|
||||||
|
public class NacosEnvironmentRepository implements EnvironmentRepository {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PersistService persistService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Environment findOne(String application, String profile, String label) {
|
||||||
|
|
||||||
|
String dataId = application + "-" + profile + ".properties";
|
||||||
|
|
||||||
|
ConfigInfo configInfo = persistService.findConfigInfo(dataId, DEFAULT_GROUP, label);
|
||||||
|
|
||||||
|
return createEnvironment(configInfo, application, profile);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Environment createEnvironment(ConfigInfo configInfo, String application, String profile) {
|
||||||
|
|
||||||
|
Environment environment = new Environment(application, profile);
|
||||||
|
|
||||||
|
Properties properties = createProperties(configInfo);
|
||||||
|
|
||||||
|
String propertySourceName = String.format("Nacos[application : %s , profile : %s]", application, profile);
|
||||||
|
|
||||||
|
PropertySource propertySource = new PropertySource(propertySourceName, properties);
|
||||||
|
|
||||||
|
environment.add(propertySource);
|
||||||
|
|
||||||
|
return environment;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Properties createProperties(ConfigInfo configInfo) {
|
||||||
|
Properties properties = new Properties();
|
||||||
|
String content = configInfo == null ? null : configInfo.getContent();
|
||||||
|
if (StringUtils.hasText(content)) {
|
||||||
|
try {
|
||||||
|
properties.load(new StringReader(content));
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IllegalStateException("The format of content is a properties");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String[] of(String... values) {
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
# Auto-Configuration
|
||||||
|
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||||
|
org.springframework.cloud.alibaba.nacos.config.server.NacosConfigServerAutoConfiguration
|
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.springframework.cloud.alibaba.nacos.config.server.bootstrap;
|
||||||
|
|
||||||
|
import org.springframework.boot.ApplicationRunner;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
|
import org.springframework.cloud.config.server.EnableConfigServer;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nacos Config Server Bootstrap
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||||
|
* @since 0.2.0
|
||||||
|
*/
|
||||||
|
@EnableAutoConfiguration
|
||||||
|
@EnableConfigServer
|
||||||
|
public class NacosConfigServerBootstrap {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.setProperty("nacos.standalone", "true");
|
||||||
|
SpringApplication.run(NacosConfigServerBootstrap.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ApplicationRunner applicationRunner() {
|
||||||
|
|
||||||
|
return args -> {
|
||||||
|
System.out.println("Running...");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,2 @@
|
|||||||
|
spring.application.name=nacos-config-server
|
||||||
|
management.endpoints.web.exposure.include=*
|
Loading…
x
Reference in New Issue
Block a user