Merge pull request from spring-cloud-incubator/master

Merge
pull/88/head
Neptune committed by GitHub
commit 256c9d367c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -48,7 +48,7 @@ Example 列表:
[Nacos Discovery Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/readme-zh.md)
[AliCloud OSS Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/storage-example/readme-zh.md)
[AliCloud OSS Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/oss-example/readme-zh.md)
## 版本管理规范
项目的版本号格式为 x.x.x 的形式,其中 x 的数值类型为数字从0开始取值且不限于 0~9 这个范围。项目处于孵化器阶段时第一位版本号固定使用0即版本号为 0.x.x 的格式。

@ -47,7 +47,7 @@ Examples
[Nacos Discovery Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/readme.md)
[AliCloud OSS Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/storage-example/readme.md)
[AliCloud OSS Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/oss-example/readme.md)
## Version control guidelines
The version number of the project is in the form of x.x.x, where x is a number, starting from 0, and is not limited to the range 0~9. When the project is in the incubator phase, the first version number is fixed to 0, that is, the version number is 0.x.x.

@ -15,7 +15,7 @@ Spring Cloud Alibaba 致力于提供分布式应用服务开发的一站式解
**Nacos**
阿里巴巴开源产品,一个更易于构建云原生应用的动态服务发现、配置管理和服务管理平台。
**Aliyun OSS**
**AliCloud OSS**
阿里云对象存储服务Object Storage Service简称 OSS是阿里云提供的海量、安全、低成本、高可靠的云存储服务。您可以在任何应用、任何时间、任何地点存储和访问任意类型的数据。
## 即将加入的组件

@ -14,7 +14,7 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba</artifactId>
<version>0.2.0.BUILD-SNAPSHOT</version>
<version>0.2.0</version>
<packaging>pom</packaging>
<name>Spring Cloud Alibaba</name>
@ -74,12 +74,14 @@
<modules>
<module>spring-cloud-alibaba-dependencies</module>
<module>spring-cloud-alibaba-sentinel</module>
<module>spring-cloud-alibaba-storage</module>
<module>spring-cloud-alibaba-nacos-config</module>
<module>spring-cloud-alibaba-nacos-discovery</module>
<module>spring-cloud-alibaba-examples</module>
<module>spring-cloud-alibaba-test</module>
<module>spring-cloud-starter-alibaba</module>
<module>spring-cloud-starter-alicloud</module>
<module>spring-cloud-alicloud-oss</module>
</modules>
<dependencyManagement>

@ -10,15 +10,15 @@
<relativePath/>
</parent>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>0.2.0.BUILD-SNAPSHOT</version>
<version>0.2.0</version>
<packaging>pom</packaging>
<name>Spring Cloud Alibaba Dependencies</name>
<description>Spring Cloud Alibaba Dependencies</description>
<properties>
<sentinel.version>0.1.1</sentinel.version>
<sentinel.version>0.2.0</sentinel.version>
<oss.version>3.1.0</oss.version>
<nacos.version>0.2.1-RC1</nacos.version>
<nacos.version>0.2.1</nacos.version>
</properties>
<dependencyManagement>
@ -81,7 +81,7 @@
</dependency>
<!-- Aliyun storage dependencies -->
<!-- Aliyun OSS dependencies -->
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
@ -97,7 +97,7 @@
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-storage</artifactId>
<artifactId>spring-cloud-alicloud-oss</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
@ -119,7 +119,7 @@
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-storage</artifactId>
<artifactId>spring-cloud-starter-alicloud-oss</artifactId>
<version>${project.version}</version>
</dependency>

@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-examples</artifactId>
<version>0.2.0.BUILD-SNAPSHOT</version>
<version>0.2.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>nacos-discovery-example</artifactId>
<version>0.2.0.BUILD-SNAPSHOT</version>
<version>0.2.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>nacos-discovery-example</artifactId>
<version>0.2.0.BUILD-SNAPSHOT</version>
<version>0.2.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-examples</artifactId>
<version>0.2.0.BUILD-SNAPSHOT</version>
<version>0.2.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

@ -5,14 +5,14 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-examples</artifactId>
<version>0.2.0.BUILD-SNAPSHOT</version>
<version>0.2.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>storage-example</artifactId>
<artifactId>oss-example</artifactId>
<packaging>jar</packaging>
<description>Example demonstrating how to use storage</description>
<description>Example demonstrating how to use alicloud oss</description>
<dependencies>
@ -22,7 +22,7 @@
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-storage</artifactId>
<artifactId>spring-cloud-starter-alicloud-oss</artifactId>
</dependency>
<dependency>

@ -1,4 +1,4 @@
# Storage Example
# OSS Example
## 项目说明
@ -13,11 +13,11 @@
**注意:本节只是为了便于您理解接入方式,本示例代码中已经完成接入工作,您只需修改 accessKeyId、secretAccessKey、region 即可。**
1. 修改 pom.xml 文件,引入 alibaba-storage starter。
1. 修改 pom.xml 文件,引入 alicloud-oss starter。
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-storage</artifactId>
<artifactId>spring-cloud-starter-alicloud-oss</artifactId>
</dependency>
2. 在配置文件中配置 OSS 服务对应的 accessKeyId、secretAccessKey 和 region。

@ -1,4 +1,4 @@
# Storage Example
# OSS Example
## Introduction
If your applications are Spring Cloud applications and you need to use Alibaba Cloud's OSS service for file storage (for example, storing commodity image for your e-commerce business), you can use OSS starter. This topic provides an example to illustrate how to use OSS starter to implement object storage for Spring Cloud applications.
@ -13,11 +13,11 @@ If your applications are Spring Cloud applications and you need to use Alibaba C
Before we start the demo, let's learn how to connect OSS to a Spring Cloud application.
**Note: This section is to show you how to connect to oss. The actual configurations have been completed in the following example, and you only need to specify your accessKeyId, secretAccessKey and region.**
1. Add dependency spring-cloud-starter-alibaba-storage in the pom.xml file in your Spring Cloud project.
1. Add dependency spring-cloud-starter-alicloud-oss in the pom.xml file in your Spring Cloud project.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-storage</artifactId>
<artifactId>spring-cloud-starter-alicloud-oss</artifactId>
</dependency>
2. Configure accessKeyId, secretAccessKey and region in application.properties.

@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba</artifactId>
<version>0.2.0.BUILD-SNAPSHOT</version>
<version>0.2.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -22,7 +22,7 @@
<module>sentinel-example/sentinel-dubbo-example/sentinel-dubbo-api</module>
<module>nacos-example/nacos-discovery-example</module>
<module>nacos-example/nacos-config-example</module>
<module>storage-example</module>
<module>oss-example</module>
</modules>
<build>

@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-examples</artifactId>
<version>0.2.0.BUILD-SNAPSHOT</version>
<version>0.2.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

@ -78,7 +78,7 @@
```
spring.application.name=sentinel-example
server.port=18083
spring.cloud.sentinel.dashboard=localhost:8080
spring.cloud.sentinel.transport.dashboard=localhost:8080
```
2. 启动应用,支持 IDE 直接启动和编译打包后启动。
@ -192,9 +192,9 @@ Sentinel 控制台支持实时监控查看,您可以通过 Sentinel 控制台
<p align="center"><img src="https://cdn.nlark.com/lark/0/2018/png/54319/1532313595369-8428cd7d-9eb7-4786-a149-acf0da4a2daf.png" width="480" heigh='180' ></p>
## DataSource 支持
## ReadableDataSource 支持
Sentinel 内部提供了[动态规则的扩展实现 DataSource](https://github.com/alibaba/Sentinel/wiki/%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%99%E6%89%A9%E5%B1%95#datasource-%E6%89%A9%E5%B1%95)。
Sentinel 内部提供了[动态规则的扩展实现 ReadableDataSource](https://github.com/alibaba/Sentinel/wiki/%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%99%E6%89%A9%E5%B1%95#datasource-%E6%89%A9%E5%B1%95)。
Sentinel starter 整合了目前存在的几类 DataSource。只需要在配置文件中进行相关配置即可在 Spring 容器中自动注册 DataSource。
@ -204,13 +204,13 @@ Sentinel starter 整合了目前存在的几类 DataSource。只需要在配置
spring.cloud.sentinel.datasource.recommendRefreshMs=2000
spring.cloud.sentinel.datasource.bufSize=2048
spring.cloud.sentinel.datasource.charset=utf-8
spring.cloud.sentinel.datasource.configParser=myParser
spring.cloud.sentinel.datasource.converter=myParser
spring.cloud.sentinel.datasource.file=/Users/you/rule.json
然后使用`@SentinelDataSource` 注解修饰 DataSource 即可注入:
@SentinelDataSource("spring.cloud.sentinel.datasource")
private DataSource dataSource;
private ReadableDataSource dataSource;
`@SentinelDataSource` 注解的 value 属性可以不填。默认值就是 `spring.cloud.sentinel.datasource`
@ -220,7 +220,7 @@ Sentinel starter 整合了目前存在的几类 DataSource。只需要在配置
`spring.cloud.sentinel.datasource.recommendRefreshMs` 里的 `recommendRefreshMs` 对应相关 DataSource 的属性。
`spring.cloud.sentinel.datasource.configParser`代表 `ConfigParser` 在 Spring 容器里的 name。如果没找到会抛出异常。
`spring.cloud.sentinel.datasource.converter`代表 `Converter` 在 Spring 容器里的 name。如果没找到会抛出异常。
type目前支持file, nacos, zk, apollo。
@ -230,7 +230,7 @@ type目前支持file, nacos, zk, apollo。
1. 定义DataSource
public class CustomDataSource implements DataSource {
public class CustomDataSource implements ReadableDataSource {
private String fieldA;
private String fieldB;
...
@ -260,7 +260,7 @@ type目前支持file, nacos, zk, apollo。
spring.cloud.sentinel.datasource.fieldA = valueA
spring.cloud.sentinel.datasource.fieldB = valueB
注意由于目前Sentinel的AbstractDataSource需要有个ConfigParser作为构造函数中的参数并且它的子类的构造都是通过多个参数的构造函数构造的。
注意由于目前Sentinel的AbstractDataSource需要有个Converter作为构造函数中的参数并且它的子类的构造都是通过多个参数的构造函数构造的。
所以目前所有的Sentinel starter中的DataSource都是基于FactoryBean并且通过设置属性构造的。如果有这方面的需求需要再多加一个registerFactoryBean过程。
SentinelDataSourceRegistry.registerFactoryBean("custeom", CustomDataSourceFactoryBean.class);

@ -66,7 +66,7 @@ Before we start the demo, let's learn how to connect Sentinel to a Spring Cloud
spring.application.name=sentinel-example
server.port=18083
spring.cloud.sentinel.dashboard=localhost:8080
spring.cloud.sentinel.transport.dashboard=localhost:8080
2. Start the application in IDE or by building a fatjar.
@ -165,9 +165,9 @@ To see the metrics, click **实时监控(Real-time Monitoring)** in the left-sid
<p align="center"><img src="https://cdn.nlark.com/lark/0/2018/png/54319/1532313595369-8428cd7d-9eb7-4786-a149-acf0da4a2daf.png" width="480" heigh='180'></p>
## DataSource
## ReadableDataSource
Sentinel provide [DataSource](https://github.com/alibaba/Sentinel/blob/master/sentinel-extension/sentinel-datasource-extension/src/main/java/com/alibaba/csp/sentinel/datasource/DataSource.java) to manage dynamic rules.
Sentinel provide [ReadableDataSource](https://github.com/alibaba/Sentinel/blob/master/sentinel-extension/sentinel-datasource-extension/src/main/java/com/alibaba/csp/sentinel/datasource/ReadableDataSource.java) to manage dynamic rules.
Sentinel starter integrated 4 DataSources provided by Sentinel. It will be register into Spring Context if you write some configs in `application.properties`.
@ -177,13 +177,13 @@ If you want to define FileRefreshableDataSource:
spring.cloud.sentinel.datasource.recommendRefreshMs=2000
spring.cloud.sentinel.datasource.bufSize=2048
spring.cloud.sentinel.datasource.charset=utf-8
spring.cloud.sentinel.datasource.configParser=myParser
spring.cloud.sentinel.datasource.converter=myParser
spring.cloud.sentinel.datasource.file=/Users/you/rule.json
then use `@SentinelDataSource` to annotate DataSource:
@SentinelDataSource("spring.cloud.sentinel.datasource")
private DataSource dataSource;
private ReadableDataSource dataSource;
The value() of `@SentinelDataSource` is not required, it means the prefix of configuration. Default value is `spring.cloud.sentinel.datasource`.
@ -191,7 +191,7 @@ spring.cloud.sentinel.datasource.type means the type of DataSource.
spring.cloud.sentinel.datasource.recommendRefreshMs means the recommendRefreshMs property of specified DataSource.
spring.cloud.sentinel.datasource.configParser means the name of spring bean that type is ConfigParser. If the bean is not exists, will throw exception.
spring.cloud.sentinel.datasource.converter means the name of spring bean that type is Converter. If the bean is not exists, will throw exception.
Now datasource type support 4 categories: file, nacos, zk, apollo.
@ -201,7 +201,7 @@ User-defined DataSource need 2 steps.
1. Define DataSource
public class CustomDataSource implements DataSource {
public class CustomDataSource implements ReadableDataSource {
private String fieldA;
private String fieldB;
...
@ -230,7 +230,7 @@ User-defined DataSource need 2 steps.
spring.cloud.sentinel.datasource.fieldA = valueA
spring.cloud.sentinel.datasource.fieldB = valueB
Note: The AbstractDataSource of Sentinel need a ConfigParser as a constructor param and the subclass of AbstractDataSource was construct by multi-param constructor.
Note: The AbstractDataSource of Sentinel need a Converter as a constructor param and the subclass of AbstractDataSource was construct by multi-param constructor.
Now All DataSources in starter was construct by FactoryBean. If you want to do it in this way, you should register FactoryBean by SentinelDataSourceRegistry.
SentinelDataSourceRegistry.registerFactoryBean("custeom", CustomDataSourceFactoryBean.class);

@ -2,7 +2,7 @@ package org.springframework.cloud.alibaba.cloud.examples;
import java.util.List;
import com.alibaba.csp.sentinel.datasource.ConfigParser;
import com.alibaba.csp.sentinel.datasource.Converter;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
@ -10,9 +10,10 @@ import com.alibaba.fastjson.TypeReference;
/**
* @author fangjian
*/
public class JsonFlowRuleListParser implements ConfigParser<String, List<FlowRule>> {
public class JsonFlowRuleListParser implements Converter<String, List<FlowRule>> {
@Override
public List<FlowRule> parse(String source) {
return JSON.parseObject(source, new TypeReference<List<FlowRule>>() {});
public List<FlowRule> convert(String source) {
return JSON.parseObject(source, new TypeReference<List<FlowRule>>() {
});
}
}

@ -1,6 +1,6 @@
package org.springframework.cloud.alibaba.cloud.examples;
import com.alibaba.csp.sentinel.datasource.ConfigParser;
import com.alibaba.csp.sentinel.datasource.Converter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.alibaba.sentinel.annotation.SentinelProtect;
@ -25,7 +25,7 @@ public class ServiceApplication {
}
@Bean
public ConfigParser myParser() {
public Converter myParser() {
return new JsonFlowRuleListParser();
}

@ -1,8 +1,8 @@
spring.application.name=sentinel-example
server.port=18083
management.endpoints.web.exposure.include=*
spring.cloud.sentinel.port=8721
spring.cloud.sentinel.dashboard=localhost:8080
spring.cloud.sentinel.transport.port=8721
spring.cloud.sentinel.transport.dashboard=localhost:8080
@ -10,5 +10,5 @@ spring.cloud.sentinel.datasource.type=file
spring.cloud.sentinel.datasource.recommendRefreshMs=3000
spring.cloud.sentinel.datasource.bufSize=4056196
spring.cloud.sentinel.datasource.charset=utf-8
spring.cloud.sentinel.datasource.configParser=myParser
spring.cloud.sentinel.datasource.converter=myParser
spring.cloud.sentinel.datasource.file=/Users/you/rule.json

@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-examples</artifactId>
<version>0.2.0.BUILD-SNAPSHOT</version>
<version>0.2.0</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-examples</artifactId>
<version>0.2.0.BUILD-SNAPSHOT</version>
<version>0.2.0</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-examples</artifactId>
<version>0.2.0.BUILD-SNAPSHOT</version>
<version>0.2.0</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba</artifactId>
<version>0.2.0.BUILD-SNAPSHOT</version>
<version>0.2.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

@ -28,6 +28,8 @@ import com.alibaba.nacos.api.exception.NacosException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.util.StringUtils;
/**
@ -83,11 +85,22 @@ public class NacosPropertySourceBuilder {
data = configService.getConfig(dataId, group, timeout);
// todo add content type yaml support
if (!StringUtils.isEmpty(data)) {
Properties properties = new Properties();
logger.info(String.format("Loading nacos data, dataId: '%s', group: '%s'",
dataId, group));
properties.load(new StringReader(data));
return properties;
if (fileExtension.equalsIgnoreCase("properties")) {
Properties properties = new Properties();
properties.load(new StringReader(data));
return properties;
}
else if (fileExtension.equalsIgnoreCase("yaml")
|| fileExtension.equalsIgnoreCase("yml")) {
YamlPropertiesFactoryBean yamlFactory = new YamlPropertiesFactoryBean();
yamlFactory.setResources(new ByteArrayResource(data.getBytes()));
return yamlFactory.getObject();
}
}
}
catch (NacosException e) {

@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba</artifactId>
<version>0.2.0.BUILD-SNAPSHOT</version>
<version>0.2.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

@ -48,12 +48,6 @@ public class NacosDiscoveryAutoConfiguration {
return new NacosServiceRegistry();
}
@Bean
@ConditionalOnMissingBean
public NacosDiscoveryProperties nacosProperties() {
return new NacosDiscoveryProperties();
}
@Bean
@ConditionalOnBean(AutoServiceRegistrationProperties.class)
public NacosRegistration nacosRegistration() {

@ -19,12 +19,15 @@ package org.springframework.cloud.alibaba.nacos;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.alibaba.nacos.registry.NacosRegistration;
import org.springframework.cloud.client.DefaultServiceInstance;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.core.env.Environment;
import java.util.*;
import javax.annotation.PostConstruct;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.pojo.ListView;
@ -39,7 +42,18 @@ public class NacosDiscoveryClient implements DiscoveryClient {
public static final String DESCRIPTION = "Spring Cloud Nacos Discovery Client";
@Autowired
private NacosRegistration nacosRegistration;
private NacosDiscoveryProperties discoveryProperties;
@Autowired
private Environment environment;
private NamingService namingService;
@PostConstruct
public void init() {
discoveryProperties.overrideFromEnv(environment);
namingService = discoveryProperties.getNamingService();
}
@Override
public String description() {
@ -49,8 +63,7 @@ public class NacosDiscoveryClient implements DiscoveryClient {
@Override
public List<ServiceInstance> getInstances(String serviceId) {
try {
NamingService namingService = nacosRegistration.getNacosNamingService();
List<Instance> instances = namingService.selectInstances(serviceId, true);
List<Instance> instances = namingService.getAllInstances(serviceId);
return hostToServiceInstanceList(instances, serviceId);
}
catch (Exception e) {
@ -79,7 +92,9 @@ public class NacosDiscoveryClient implements DiscoveryClient {
List<Instance> instances, String serviceId) {
List<ServiceInstance> result = new ArrayList<ServiceInstance>(instances.size());
for (Instance instance : instances) {
result.add(hostToServiceInstance(instance, serviceId));
if (instance.isHealthy()) {
result.add(hostToServiceInstance(instance, serviceId));
}
}
return result;
}
@ -88,7 +103,6 @@ public class NacosDiscoveryClient implements DiscoveryClient {
public List<String> getServices() {
try {
NamingService namingService = nacosRegistration.getNacosNamingService();
ListView<String> services = namingService.getServicesOfServer(1,
Integer.MAX_VALUE);
return services.getData();
@ -99,4 +113,7 @@ public class NacosDiscoveryClient implements DiscoveryClient {
}
}
public NamingService getNamingService() {
return namingService;
}
}

@ -36,4 +36,10 @@ public class NacosDiscoveryClientAutoConfiguration {
return new NacosDiscoveryClient();
}
@Bean
@ConditionalOnMissingBean
public NacosDiscoveryProperties nacosProperties() {
return new NacosDiscoveryProperties();
}
}

@ -16,6 +16,8 @@
package org.springframework.cloud.alibaba.nacos;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ -33,6 +35,18 @@ import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.client.naming.utils.UtilAndComs;
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.ENDPOINT;
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;
/**
* @author dungu.zpf
@ -42,6 +56,9 @@ import java.util.Objects;
@ConfigurationProperties("spring.cloud.nacos.discovery")
public class NacosDiscoveryProperties {
private static final Logger LOGGER = LoggerFactory
.getLogger(NacosDiscoveryProperties.class);
/**
* nacos discovery server address
*/
@ -333,4 +350,22 @@ public class NacosDiscoveryProperties {
}
}
public NamingService getNamingService() {
Properties properties = new Properties();
properties.put(SERVER_ADDR, serverAddr);
properties.put(NAMESPACE, namespace);
properties.put(UtilAndComs.NACOS_NAMING_LOG_NAME, logName);
properties.put(ENDPOINT, endpoint);
properties.put(ACCESS_KEY, accessKey);
properties.put(SECRET_KEY, secretKey);
properties.put(CLUSTER_NAME, clusterName);
try {
return NacosFactory.createNamingService(properties);
}
catch (Exception e) {
LOGGER.error("create naming service error!properties={},e=,", this, e);
return null;
}
}
}

@ -29,8 +29,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.cloud.alibaba.nacos.NacosDiscoveryClient;
import org.springframework.cloud.alibaba.nacos.NacosDiscoveryProperties;
import org.springframework.cloud.alibaba.nacos.registry.NacosRegistration;
/**
* Endpoint for nacos discovery, get nacos properties and subscribed services
@ -46,7 +46,7 @@ public class NacosDiscoveryEndpoint {
private NacosDiscoveryProperties nacosDiscoveryProperties;
@Autowired
private NacosRegistration nacosRegistration;
private NacosDiscoveryClient discoveryClient;
/**
* @return nacos discovery endpoint
@ -56,7 +56,7 @@ public class NacosDiscoveryEndpoint {
Map<String, Object> result = new HashMap<>();
result.put("NacosDiscoveryProperties", nacosDiscoveryProperties);
NamingService namingService = nacosRegistration.getNacosNamingService();
NamingService namingService = discoveryClient.getNamingService();
List<ServiceInfo> subscribe = Collections.emptyList();
try {

@ -28,7 +28,6 @@ import org.springframework.context.annotation.Configuration;
* @author xiaojing
*/
@Configuration
@ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled", matchIfMissing = true)
@ConditionalOnClass(Endpoint.class)
public class NacosDiscoveryEndpointAutoConfiguration {

@ -20,52 +20,56 @@ import org.springframework.cloud.alibaba.nacos.NacosDiscoveryProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.DefaultServiceInstance;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.ManagementServerPortUtils;
import org.springframework.cloud.client.serviceregistry.Registration;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;
import java.net.URI;
import java.util.Map;
import java.util.Properties;
import javax.annotation.PostConstruct;
import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.client.naming.utils.UtilAndComs;
import static com.alibaba.nacos.api.PropertyKeyConst.*;
/**
* @author xiaojing
*/
public class NacosRegistration implements Registration, ServiceInstance {
private static final String MANAGEMENT_PORT = "management.port";
private static final String MANAGEMENT_CONTEXT_PATH = "management.context-path";
private static final String MANAGEMENT_ADDRESS = "management.address";
@Autowired
private NacosDiscoveryProperties nacosDiscoveryProperties;
private NamingService nacosNamingService;
@Autowired
private Environment environment;
private ApplicationContext context;
private NamingService nacosNamingService;
@PostConstruct
public void init() {
nacosDiscoveryProperties.overrideFromEnv(environment);
Properties properties = new Properties();
properties.put(SERVER_ADDR, nacosDiscoveryProperties.getServerAddr());
properties.put(NAMESPACE, nacosDiscoveryProperties.getNamespace());
properties.put(UtilAndComs.NACOS_NAMING_LOG_NAME,
nacosDiscoveryProperties.getLogName());
properties.put(ENDPOINT, nacosDiscoveryProperties.getEndpoint());
properties.put(ACCESS_KEY, nacosDiscoveryProperties.getAccessKey());
properties.put(SECRET_KEY, nacosDiscoveryProperties.getSecretKey());
properties.put(CLUSTER_NAME, nacosDiscoveryProperties.getClusterName());
try {
nacosNamingService = NacosFactory.createNamingService(properties);
}
catch (Exception e) {
Environment env = context.getEnvironment();
nacosDiscoveryProperties.overrideFromEnv(context.getEnvironment());
nacosNamingService = nacosDiscoveryProperties.getNamingService();
Integer managementPort = ManagementServerPortUtils.getPort(context);
if (null != managementPort) {
Map<String, String> metadata = nacosDiscoveryProperties.getMetadata();
metadata.put(MANAGEMENT_PORT, managementPort.toString());
String contextPath = env
.getProperty("management.server.servlet.context-path");
String address = env.getProperty("management.server.address");
if (!StringUtils.isEmpty(contextPath)) {
metadata.put(MANAGEMENT_CONTEXT_PATH, contextPath);
}
if (!StringUtils.isEmpty(address)) {
metadata.put(MANAGEMENT_ADDRESS, address);
}
}
}
@ -85,9 +89,7 @@ public class NacosRegistration implements Registration, ServiceInstance {
}
public void setPort(int port) {
if (nacosDiscoveryProperties.getPort() < 0) {
this.nacosDiscoveryProperties.setPort(port);
}
this.nacosDiscoveryProperties.setPort(port);
}
@Override

@ -19,7 +19,7 @@ package org.springframework.cloud.alibaba.nacos.ribbon;
import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.AbstractServerList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.alibaba.nacos.registry.NacosRegistration;
import org.springframework.cloud.alibaba.nacos.NacosDiscoveryClient;
import java.util.ArrayList;
import java.util.List;
@ -32,7 +32,7 @@ import com.alibaba.nacos.api.naming.pojo.Instance;
public class NacosServerList extends AbstractServerList<NacosServer> {
@Autowired
private NacosRegistration registration;
private NacosDiscoveryClient discoveryClient;
private String serviceId;
@ -55,7 +55,7 @@ public class NacosServerList extends AbstractServerList<NacosServer> {
private List<NacosServer> getServers() {
try {
List<Instance> instances = registration.getNacosNamingService()
List<Instance> instances = discoveryClient.getNamingService()
.getAllInstances(serviceId);
return instancesToServerList(instances);
}

@ -37,7 +37,8 @@ public class NacosDiscoveryAutoConfigurationTests {
private WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
.withConfiguration(
AutoConfigurations.of(NacosDiscoveryTestConfiguration.class,
NacosDiscoveryAutoConfiguration.class))
NacosDiscoveryAutoConfiguration.class,
NacosDiscoveryClientAutoConfiguration.class))
.withPropertyValues("spring.cloud.nacos.discovery.server-addr=127.0.0.1:8080")
.withPropertyValues("spring.cloud.nacos.discovery.port=18080")
.withPropertyValues("spring.cloud.nacos.discovery.service=myapp");

@ -6,6 +6,7 @@ import org.junit.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import org.springframework.cloud.alibaba.nacos.NacosDiscoveryClientAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
@ -19,49 +20,43 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public class NacosRibbonClientConfigurationTests {
private WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
.withConfiguration(
AutoConfigurations.of(NacosRibbonTestConfiguration.class,
NacosRibbonClientConfiguration.class,
RibbonNacosAutoConfiguration.class))
.withPropertyValues("spring.cloud.nacos.discovery.server-addr=127.0.0.1:8080")
.withPropertyValues("spring.cloud.nacos.discovery.port=18080")
.withPropertyValues("spring.cloud.nacos.discovery.service=myapp");
@Test
public void testProperties() {
this.contextRunner.run(context -> {
NacosServerList serverList = context.getBean(NacosServerList.class);
assertThat(serverList.getServiceId()).isEqualTo("myapp");
});
}
@Configuration
@EnableAutoConfiguration
@EnableDiscoveryClient
static class NacosRibbonTestConfiguration {
@Bean
IClientConfig iClientConfig(){
//return new IClientConfig.Builder().s.build();
DefaultClientConfigImpl config = new DefaultClientConfigImpl();
config.setClientName("myapp");
return config;
}
@Bean
@LoadBalanced
RestTemplate restTemplate(){
return new RestTemplate();
}
}
private WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(NacosRibbonTestConfiguration.class,
NacosRibbonClientConfiguration.class,
NacosDiscoveryClientAutoConfiguration.class,
RibbonNacosAutoConfiguration.class))
.withPropertyValues("spring.cloud.nacos.discovery.server-addr=127.0.0.1:8080")
.withPropertyValues("spring.cloud.nacos.discovery.port=18080")
.withPropertyValues("spring.cloud.nacos.discovery.service=myapp");
@Test
public void testProperties() {
this.contextRunner.run(context -> {
NacosServerList serverList = context.getBean(NacosServerList.class);
assertThat(serverList.getServiceId()).isEqualTo("myapp");
});
}
@Configuration
@EnableAutoConfiguration
@EnableDiscoveryClient
static class NacosRibbonTestConfiguration {
@Bean
IClientConfig iClientConfig() {
// return new IClientConfig.Builder().s.build();
DefaultClientConfigImpl config = new DefaultClientConfigImpl();
config.setClientName("myapp");
return config;
}
@Bean
@LoadBalanced
RestTemplate restTemplate() {
return new RestTemplate();
}
}
}

@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba</artifactId>
<version>0.2.0.BUILD-SNAPSHOT</version>
<version>0.2.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

@ -22,53 +22,119 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.core.Ordered;
import com.alibaba.csp.sentinel.config.SentinelConfig;
import com.alibaba.csp.sentinel.transport.config.TransportConfig;
/**
* @author xiaojing
* @author hengyunabc
* @author jiashuai.xie
*/
@ConfigurationProperties(prefix = SentinelConstants.PROPERTY_PREFIX)
public class SentinelProperties {
/**
* Enable sentinel auto configure, the default value is true
* earlier initialize heart-beat when the spring container starts <note> when the
* transport dependency is on classpath ,the configuration is effective </note>
*/
private boolean eager = false;
/**
* enable sentinel auto configure, the default value is true
*/
private boolean enabled = true;
/**
* sentinel api port,default value is 8721
* charset when sentinel write or search metric file {@link SentinelConfig#CHARSET}
*/
private String port = "8721";
private String charset = "UTF-8";
/**
* Sentinel dashboard address, won't try to connect dashboard when address is empty
* transport configuration about dashboard and client
*/
private String dashboard = "";
@NestedConfigurationProperty
private Transport transport = new Transport();
/**
* metric configuration about resource
*/
@NestedConfigurationProperty
private Filter filter;
private Metric metric = new Metric();
public boolean isEnabled() {
return enabled;
/**
* web servlet configuration <note> when the application is web ,the configuration is
* effective </note>
*/
@NestedConfigurationProperty
private Servlet servlet = new Servlet();
/**
* sentinel filter <note> when the application is web ,the configuration is effective
* </note>
*/
@NestedConfigurationProperty
private Filter filter = new Filter();
/**
* flow configuration
*/
@NestedConfigurationProperty
private Flow flow = new Flow();
public boolean isEager() {
return eager;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
public void setEager(boolean eager) {
this.eager = eager;
}
public Flow getFlow() {
return flow;
}
public void setFlow(Flow flow) {
this.flow = flow;
}
public String getCharset() {
return charset;
}
public void setCharset(String charset) {
this.charset = charset;
}
public Transport getTransport() {
return transport;
}
public void setTransport(Transport transport) {
this.transport = transport;
}
public Metric getMetric() {
return metric;
}
public void setMetric(Metric metric) {
this.metric = metric;
}
public String getPort() {
return port;
public Servlet getServlet() {
return servlet;
}
public void setPort(String port) {
this.port = port;
public void setServlet(Servlet servlet) {
this.servlet = servlet;
}
public String getDashboard() {
return dashboard;
public boolean isEnabled() {
return enabled;
}
public void setDashboard(String dashboard) {
this.dashboard = dashboard;
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public Filter getFilter() {
@ -79,10 +145,117 @@ public class SentinelProperties {
this.filter = filter;
}
public static class Flow {
/**
* the cold factor {@link SentinelConfig#COLD_FACTOR}
*/
private String coldFactor = "3";
public String getColdFactor() {
return coldFactor;
}
public void setColdFactor(String coldFactor) {
this.coldFactor = coldFactor;
}
}
public static class Servlet {
/**
* The process page when the flow control is triggered
*/
private String blockPage;
public String getBlockPage() {
return blockPage;
}
public void setBlockPage(String blockPage) {
this.blockPage = blockPage;
}
}
public static class Metric {
/**
* the metric file size {@link SentinelConfig#SINGLE_METRIC_FILE_SIZE}
*/
private String fileSingleSize;
/**
* the total metric file count {@link SentinelConfig#TOTAL_METRIC_FILE_COUNT}
*/
private String fileTotalCount;
public String getFileSingleSize() {
return fileSingleSize;
}
public void setFileSingleSize(String fileSingleSize) {
this.fileSingleSize = fileSingleSize;
}
public String getFileTotalCount() {
return fileTotalCount;
}
public void setFileTotalCount(String fileTotalCount) {
this.fileTotalCount = fileTotalCount;
}
}
public static class Transport {
/**
* sentinel api port,default value is 8721 {@link TransportConfig#SERVER_PORT}
*/
private String port = "8721";
/**
* sentinel dashboard address, won't try to connect dashboard when address is
* empty {@link TransportConfig#CONSOLE_SERVER}
*/
private String dashboard = "";
/**
* send heartbeat interval millisecond
* {@link TransportConfig#HEARTBEAT_INTERVAL_MS}
*/
private String heartbeatIntervalMs;
public String getHeartbeatIntervalMs() {
return heartbeatIntervalMs;
}
public void setHeartbeatIntervalMs(String heartbeatIntervalMs) {
this.heartbeatIntervalMs = heartbeatIntervalMs;
}
public String getPort() {
return port;
}
public void setPort(String port) {
this.port = port;
}
public String getDashboard() {
return dashboard;
}
public void setDashboard(String dashboard) {
this.dashboard = dashboard;
}
}
public static class Filter {
/**
* Sentinel filter chain order.
* sentinel filter chain order.
*/
private int order = Ordered.HIGHEST_PRECEDENCE;
@ -107,4 +280,5 @@ public class SentinelProperties {
this.urlPatterns = urlPatterns;
}
}
}

@ -16,28 +16,34 @@
package org.springframework.cloud.alibaba.sentinel.annotation;
import java.lang.annotation.*;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import com.alibaba.csp.sentinel.datasource.ReadableDataSource;
import org.springframework.core.annotation.AliasFor;
/**
* An annotation to inject {@link com.alibaba.csp.sentinel.datasource.DataSource} instance
* An annotation to inject {@link ReadableDataSource} instance
* into a Spring Bean. The Properties of DataSource bean get from config files with
* specific prefix.
*
* @author fangjian
* @see com.alibaba.csp.sentinel.datasource.DataSource
* @see ReadableDataSource
*/
@Target({ ElementType.FIELD })
@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface SentinelDataSource {
@AliasFor("prefix")
String value() default "";
@AliasFor("prefix")
String value() default "";
@AliasFor("value")
String prefix() default "";
@AliasFor("value")
String prefix() default "";
String name() default ""; // spring bean name

@ -18,14 +18,9 @@ package org.springframework.cloud.alibaba.sentinel.custom;
import java.util.Optional;
import com.alibaba.csp.sentinel.adapter.servlet.callback.UrlBlockHandler;
import com.alibaba.csp.sentinel.adapter.servlet.callback.UrlCleaner;
import com.alibaba.csp.sentinel.adapter.servlet.callback.WebCallbackManager;
import com.alibaba.csp.sentinel.init.InitExecutor;
import com.alibaba.csp.sentinel.transport.config.TransportConfig;
import com.alibaba.csp.sentinel.util.AppNameUtil;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@ -36,14 +31,20 @@ import org.springframework.cloud.alibaba.sentinel.datasource.SentinelDataSourceP
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;
import com.alibaba.csp.sentinel.adapter.servlet.callback.UrlBlockHandler;
import com.alibaba.csp.sentinel.adapter.servlet.callback.UrlCleaner;
import com.alibaba.csp.sentinel.adapter.servlet.callback.WebCallbackManager;
import com.alibaba.csp.sentinel.adapter.servlet.config.WebServletConfig;
import com.alibaba.csp.sentinel.annotation.aspectj.SentinelResourceAspect;
import javax.annotation.PostConstruct;
import com.alibaba.csp.sentinel.config.SentinelConfig;
import com.alibaba.csp.sentinel.init.InitExecutor;
import com.alibaba.csp.sentinel.transport.config.TransportConfig;
import com.alibaba.csp.sentinel.util.AppNameUtil;
/**
* @author xiaojing
* @author jiashuai.xie
*/
@Configuration
@ConditionalOnProperty(name = "spring.cloud.sentinel.enabled", matchIfMissing = true)
@ -57,27 +58,67 @@ public class SentinelAutoConfiguration {
private SentinelProperties properties;
@Autowired
private Optional<UrlBlockHandler> urlBlockHandlerOptional;
private Optional<UrlCleaner> urlCleanerOptional;
@Autowired
private Optional<UrlCleaner> urlCleanerOptional;
private Optional<UrlBlockHandler> urlBlockHandlerOptional;
@PostConstruct
private void init() {
if (StringUtils.isEmpty(System.getProperty(AppNameUtil.APP_NAME))) {
if (StringUtils.isEmpty(System.getProperty(AppNameUtil.APP_NAME))
&& StringUtils.hasText(projectName)) {
System.setProperty(AppNameUtil.APP_NAME, projectName);
}
if (StringUtils.isEmpty(System.getProperty(TransportConfig.SERVER_PORT))) {
System.setProperty(TransportConfig.SERVER_PORT, properties.getPort());
if (StringUtils.isEmpty(System.getProperty(TransportConfig.SERVER_PORT))
&& StringUtils.hasText(properties.getTransport().getPort())) {
System.setProperty(TransportConfig.SERVER_PORT,
properties.getTransport().getPort());
}
if (StringUtils.isEmpty(System.getProperty(TransportConfig.CONSOLE_SERVER))
&& StringUtils.hasText(properties.getTransport().getDashboard())) {
System.setProperty(TransportConfig.CONSOLE_SERVER,
properties.getTransport().getDashboard());
}
if (StringUtils.isEmpty(System.getProperty(TransportConfig.CONSOLE_SERVER))) {
System.setProperty(TransportConfig.CONSOLE_SERVER, properties.getDashboard());
if (StringUtils.isEmpty(System.getProperty(TransportConfig.HEARTBEAT_INTERVAL_MS))
&& StringUtils
.hasText(properties.getTransport().getHeartbeatIntervalMs())) {
System.setProperty(TransportConfig.HEARTBEAT_INTERVAL_MS,
properties.getTransport().getHeartbeatIntervalMs());
}
if (StringUtils.isEmpty(System.getProperty(SentinelConfig.CHARSET))
&& StringUtils.hasText(properties.getCharset())) {
System.setProperty(SentinelConfig.CHARSET, properties.getCharset());
}
if (StringUtils
.isEmpty(System.getProperty(SentinelConfig.SINGLE_METRIC_FILE_SIZE))
&& StringUtils.hasText(properties.getMetric().getFileSingleSize())) {
System.setProperty(SentinelConfig.SINGLE_METRIC_FILE_SIZE,
properties.getMetric().getFileSingleSize());
}
if (StringUtils
.isEmpty(System.getProperty(SentinelConfig.TOTAL_METRIC_FILE_COUNT))
&& StringUtils.hasText(properties.getMetric().getFileTotalCount())) {
System.setProperty(SentinelConfig.TOTAL_METRIC_FILE_COUNT,
properties.getMetric().getFileTotalCount());
}
if (StringUtils.isEmpty(System.getProperty(SentinelConfig.COLD_FACTOR))
&& StringUtils.hasText(properties.getFlow().getColdFactor())) {
System.setProperty(SentinelConfig.COLD_FACTOR,
properties.getFlow().getColdFactor());
}
if (StringUtils.hasText(properties.getServlet().getBlockPage())) {
WebServletConfig.setBlockPage(properties.getServlet().getBlockPage());
}
urlBlockHandlerOptional.ifPresent(WebCallbackManager::setUrlBlockHandler);
urlCleanerOptional.ifPresent(WebCallbackManager::setUrlCleaner);
InitExecutor.doInit();
// earlier initialize
if (properties.isEager()) {
InitExecutor.doInit();
}
}
@Bean

@ -34,10 +34,10 @@ import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import com.alibaba.csp.sentinel.datasource.DataSource;
import com.alibaba.csp.sentinel.datasource.ReadableDataSource;
/**
* {@link DataSource} Loader
* {@link ReadableDataSource} Loader
*
* @author fangjian
*/
@ -50,20 +50,20 @@ public class DataSourceLoader {
private final static String ALL_PROPERTIES_RESOURCES_LOCATION = CLASSPATH_ALL_URL_PREFIX
+ PROPERTIES_RESOURCE_LOCATION;
private final static ConcurrentMap<String, Class<? extends DataSource>> dataSourceClassesCache = new ConcurrentHashMap<String, Class<? extends DataSource>>(
private final static ConcurrentMap<String, Class<? extends ReadableDataSource>> dataSourceClassesCache = new ConcurrentHashMap<String, Class<? extends ReadableDataSource>>(
4);
static void loadAllDataSourceClassesCache() {
Map<String, Class<? extends DataSource>> dataSourceClassesMap = loadAllDataSourceClassesCache(
Map<String, Class<? extends ReadableDataSource>> dataSourceClassesMap = loadAllDataSourceClassesCache(
ALL_PROPERTIES_RESOURCES_LOCATION);
dataSourceClassesCache.putAll(dataSourceClassesMap);
}
static Map<String, Class<? extends DataSource>> loadAllDataSourceClassesCache(
static Map<String, Class<? extends ReadableDataSource>> loadAllDataSourceClassesCache(
String resourcesLocation) {
Map<String, Class<? extends DataSource>> dataSourcesMap = new HashMap<String, Class<? extends DataSource>>(
Map<String, Class<? extends ReadableDataSource>> dataSourcesMap = new HashMap<String, Class<? extends ReadableDataSource>>(
4);
ClassLoader classLoader = DataSourceLoader.class.getClassLoader();
@ -102,10 +102,10 @@ public class DataSourceLoader {
Class<?> dataSourceClass = ClassUtils.resolveClassName(className,
classLoader);
Assert.isAssignable(DataSource.class, dataSourceClass);
Assert.isAssignable(ReadableDataSource.class, dataSourceClass);
dataSourcesMap.put(type,
(Class<? extends DataSource>) dataSourceClass);
(Class<? extends ReadableDataSource>) dataSourceClass);
if (logger.isDebugEnabled()) {
logger.debug("Sentinel DataSource implementation [ type : "
@ -126,10 +126,10 @@ public class DataSourceLoader {
return dataSourcesMap;
}
public static Class<? extends DataSource> loadClass(String type)
public static Class<? extends ReadableDataSource> loadClass(String type)
throws IllegalArgumentException {
Class<? extends DataSource> dataSourceClass = dataSourceClassesCache.get(type);
Class<? extends ReadableDataSource> dataSourceClass = dataSourceClassesCache.get(type);
if (dataSourceClass == null) {
if (dataSourceClassesCache.isEmpty()) {

@ -36,28 +36,40 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.cloud.alibaba.sentinel.SentinelConstants;
import org.springframework.cloud.alibaba.sentinel.annotation.SentinelDataSource;
import org.springframework.cloud.alibaba.sentinel.util.PropertySourcesUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.event.EventListener;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
import com.alibaba.csp.sentinel.datasource.ConfigParser;
import com.alibaba.csp.sentinel.datasource.Converter;
import com.alibaba.csp.sentinel.datasource.ReadableDataSource;
import com.alibaba.csp.sentinel.property.SentinelProperty;
import com.alibaba.csp.sentinel.slots.block.authority.AuthorityRule;
import com.alibaba.csp.sentinel.slots.block.authority.AuthorityRuleManager;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
import com.alibaba.csp.sentinel.slots.system.SystemRule;
import com.alibaba.csp.sentinel.slots.system.SystemRuleManager;
/**
* {@link SentinelDataSource @SentinelDataSource} Post Processor
*
* @author fangjian
* @see com.alibaba.csp.sentinel.datasource.DataSource
* @see com.alibaba.csp.sentinel.datasource.ReadableDataSource
* @see SentinelDataSource
*/
public class SentinelDataSourcePostProcessor
extends InstantiationAwareBeanPostProcessorAdapter
implements MergedBeanDefinitionPostProcessor {
private static final Logger logger = LoggerFactory
private static final Logger logger = LoggerFactory
.getLogger(SentinelDataSourcePostProcessor.class);
@Autowired
@ -170,8 +182,8 @@ public class SentinelDataSourcePostProcessor
for (String propertyName : propertyMap.keySet()) {
Field field = ReflectionUtils.findField(targetClass, propertyName);
if (field != null) {
if (field.getType().isAssignableFrom(ConfigParser.class)) {
// ConfigParser get from ApplicationContext
if (field.getType().isAssignableFrom(Converter.class)) {
// Converter get from ApplicationContext
builder.addPropertyReference(propertyName,
propertyMap.get(propertyName).toString());
}
@ -187,7 +199,42 @@ public class SentinelDataSourcePostProcessor
beanFactory.registerBeanDefinition(beanName, builder.getBeanDefinition());
}
class SentinelDataSourceField {
@EventListener(classes = ApplicationStartedEvent.class)
public void appStartedListener(ApplicationStartedEvent event) throws Exception {
Map<String, ReadableDataSource> dataSourceMap = event.getApplicationContext().getBeansOfType(ReadableDataSource.class);
if(dataSourceMap.size() == 1) {
ReadableDataSource dataSource = dataSourceMap.values().iterator().next();
Object ruleConfig = dataSource.loadConfig();
SentinelProperty sentinelProperty = dataSource.getProperty();
if(checkRuleType(ruleConfig, FlowRule.class)) {
FlowRuleManager.register2Property(sentinelProperty);
}
if(checkRuleType(ruleConfig, DegradeRule.class)) {
DegradeRuleManager.register2Property(sentinelProperty);
}
if(checkRuleType(ruleConfig, SystemRule.class)) {
SystemRuleManager.register2Property(sentinelProperty);
}
if(checkRuleType(ruleConfig, AuthorityRule.class)) {
AuthorityRuleManager.register2Property(sentinelProperty);
}
}
}
private boolean checkRuleType(Object ruleConfig, Class type) {
if(ruleConfig.getClass() == type) {
return true;
} else if(ruleConfig instanceof List) {
List ruleList = (List)ruleConfig;
if(ruleList.stream().filter(rule -> rule.getClass() == type).toArray().length == ruleList.size()) {
return true;
}
}
return false;
}
class SentinelDataSourceField {
private SentinelDataSource sentinelDataSource;
private Field field;

@ -18,6 +18,8 @@ package org.springframework.cloud.alibaba.sentinel.datasource;
import java.util.concurrent.ConcurrentHashMap;
import com.alibaba.csp.sentinel.datasource.ReadableDataSource;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.cloud.alibaba.sentinel.datasource.factorybean.ApolloDataSourceFactoryBean;
import org.springframework.cloud.alibaba.sentinel.datasource.factorybean.FileRefreshableDataSourceFactoryBean;
@ -28,7 +30,7 @@ import org.springframework.cloud.alibaba.sentinel.datasource.factorybean.Zookeep
* Registry to save DataSource FactoryBean
*
* @author fangjian
* @see com.alibaba.csp.sentinel.datasource.DataSource
* @see ReadableDataSource
* @see FileRefreshableDataSourceFactoryBean
* @see ZookeeperDataSourceFactoryBean
* @see NacosDataSourceFactoryBean
@ -36,32 +38,32 @@ import org.springframework.cloud.alibaba.sentinel.datasource.factorybean.Zookeep
*/
public class SentinelDataSourceRegistry {
private static ConcurrentHashMap<String, Class<? extends FactoryBean>> cache = new ConcurrentHashMap<>(
32);
private static ConcurrentHashMap<String, Class<? extends FactoryBean>> cache = new ConcurrentHashMap<>(
32);
static {
SentinelDataSourceRegistry.registerFactoryBean("file",
FileRefreshableDataSourceFactoryBean.class);
SentinelDataSourceRegistry.registerFactoryBean("zk",
ZookeeperDataSourceFactoryBean.class);
SentinelDataSourceRegistry.registerFactoryBean("nacos",
NacosDataSourceFactoryBean.class);
SentinelDataSourceRegistry.registerFactoryBean("apollo",
ApolloDataSourceFactoryBean.class);
}
static {
SentinelDataSourceRegistry.registerFactoryBean("file",
FileRefreshableDataSourceFactoryBean.class);
SentinelDataSourceRegistry.registerFactoryBean("zk",
ZookeeperDataSourceFactoryBean.class);
SentinelDataSourceRegistry.registerFactoryBean("nacos",
NacosDataSourceFactoryBean.class);
SentinelDataSourceRegistry.registerFactoryBean("apollo",
ApolloDataSourceFactoryBean.class);
}
public static synchronized void registerFactoryBean(String alias,
Class<? extends FactoryBean> clazz) {
cache.putIfAbsent(alias, clazz);
cache.put(alias, clazz);
}
public static synchronized void registerFactoryBean(String alias,
Class<? extends FactoryBean> clazz) {
cache.putIfAbsent(alias, clazz);
cache.put(alias, clazz);
}
public static Class<? extends FactoryBean> getFactoryBean(String alias) {
return cache.get(alias);
}
public static Class<? extends FactoryBean> getFactoryBean(String alias) {
return cache.get(alias);
}
public static boolean checkFactoryBean(String alias) {
return cache.containsKey(alias);
}
public static boolean checkFactoryBean(String alias) {
return cache.containsKey(alias);
}
}

@ -2,7 +2,7 @@ package org.springframework.cloud.alibaba.sentinel.datasource.factorybean;
import org.springframework.beans.factory.FactoryBean;
import com.alibaba.csp.sentinel.datasource.ConfigParser;
import com.alibaba.csp.sentinel.datasource.Converter;
import com.alibaba.csp.sentinel.datasource.apollo.ApolloDataSource;
/**
@ -14,12 +14,12 @@ public class ApolloDataSourceFactoryBean implements FactoryBean<ApolloDataSource
private String namespaceName;
private String flowRulesKey;
private String defaultFlowRuleValue;
private ConfigParser configParser;
private Converter converter;
@Override
public ApolloDataSource getObject() throws Exception {
return new ApolloDataSource(namespaceName, flowRulesKey, defaultFlowRuleValue,
configParser);
converter);
}
@Override
@ -51,11 +51,11 @@ public class ApolloDataSourceFactoryBean implements FactoryBean<ApolloDataSource
this.defaultFlowRuleValue = defaultFlowRuleValue;
}
public ConfigParser getConfigParser() {
return configParser;
public Converter getConverter() {
return converter;
}
public void setConfigParser(ConfigParser configParser) {
this.configParser = configParser;
public void setConverter(Converter Converter) {
this.converter = Converter;
}
}

@ -5,7 +5,7 @@ import java.nio.charset.Charset;
import org.springframework.beans.factory.FactoryBean;
import com.alibaba.csp.sentinel.datasource.ConfigParser;
import com.alibaba.csp.sentinel.datasource.Converter;
import com.alibaba.csp.sentinel.datasource.FileRefreshableDataSource;
/**
@ -19,11 +19,11 @@ public class FileRefreshableDataSourceFactoryBean
private String charset;
private long recommendRefreshMs;
private int bufSize;
private ConfigParser configParser;
private Converter converter;
@Override
public FileRefreshableDataSource getObject() throws Exception {
return new FileRefreshableDataSource(new File(file), configParser,
return new FileRefreshableDataSource(new File(file), converter,
recommendRefreshMs, bufSize, Charset.forName(charset));
}
@ -64,11 +64,11 @@ public class FileRefreshableDataSourceFactoryBean
this.bufSize = bufSize;
}
public ConfigParser getConfigParser() {
return configParser;
public Converter getConverter() {
return converter;
}
public void setConfigParser(ConfigParser configParser) {
this.configParser = configParser;
public void setConverter(Converter Converter) {
this.converter = Converter;
}
}

@ -2,7 +2,7 @@ package org.springframework.cloud.alibaba.sentinel.datasource.factorybean;
import org.springframework.beans.factory.FactoryBean;
import com.alibaba.csp.sentinel.datasource.ConfigParser;
import com.alibaba.csp.sentinel.datasource.Converter;
import com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource;
/**
@ -14,11 +14,11 @@ public class NacosDataSourceFactoryBean implements FactoryBean<NacosDataSource>
private String serverAddr;
private String groupId;
private String dataId;
private ConfigParser configParser;
private Converter converter;
@Override
public NacosDataSource getObject() throws Exception {
return new NacosDataSource(serverAddr, groupId, dataId, configParser);
return new NacosDataSource(serverAddr, groupId, dataId, converter);
}
@Override
@ -50,11 +50,11 @@ public class NacosDataSourceFactoryBean implements FactoryBean<NacosDataSource>
this.dataId = dataId;
}
public ConfigParser getConfigParser() {
return configParser;
public Converter getConverter() {
return converter;
}
public void setConfigParser(ConfigParser configParser) {
this.configParser = configParser;
public void setConverter(Converter Converter) {
this.converter = Converter;
}
}

@ -3,7 +3,7 @@ package org.springframework.cloud.alibaba.sentinel.datasource.factorybean;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.FactoryBean;
import com.alibaba.csp.sentinel.datasource.ConfigParser;
import com.alibaba.csp.sentinel.datasource.Converter;
import com.alibaba.csp.sentinel.datasource.zookeeper.ZookeeperDataSource;
/**
@ -19,17 +19,17 @@ public class ZookeeperDataSourceFactoryBean implements FactoryBean<ZookeeperData
private String groupId;
private String dataId;
private ConfigParser configParser;
private Converter converter;
@Override
public ZookeeperDataSource getObject() throws Exception {
if (StringUtils.isNotEmpty(groupId) && StringUtils.isNotEmpty(dataId)) {
// the path will be /{groupId}/{dataId}
return new ZookeeperDataSource(serverAddr, groupId, dataId, configParser);
// the path will be /{groupId}/{dataId}
return new ZookeeperDataSource(serverAddr, groupId, dataId, converter);
}
else {
// using path directly
return new ZookeeperDataSource(serverAddr, path, configParser);
// using path directly
return new ZookeeperDataSource(serverAddr, path, converter);
}
}
@ -70,11 +70,11 @@ public class ZookeeperDataSourceFactoryBean implements FactoryBean<ZookeeperData
this.dataId = dataId;
}
public ConfigParser getConfigParser() {
return configParser;
public Converter getConverter() {
return converter;
}
public void setConfigParser(ConfigParser configParser) {
this.configParser = configParser;
public void setConverter(Converter Converter) {
this.converter = Converter;
}
}

@ -7,26 +7,59 @@
"description": "enable or disable sentinel auto configure."
},
{
"name": "spring.cloud.sentinel.port",
"name": "spring.cloud.sentinel.eager",
"type": "java.lang.Boolean",
"defaultValue": false,
"description": "earlier initialize heart-beat when the spring container starts when the transport dependency is on classpath, the configuration is effective."
},
{
"name": "spring.cloud.sentinel.charset",
"type": "java.lang.String",
"defaultValue": "UTF-8",
"description": "charset when sentinel write or search metric file."
},
{
"name": "spring.cloud.sentinel.transport.port",
"type": "java.lang.String",
"defaultValue": "8721",
"description": "sentinel api port."
},
{
"name": "spring.cloud.sentinel.dashboard",
"name": "spring.cloud.sentinel.transport.dashboard",
"type": "java.lang.String",
"description": "sentinel dashboard address, won't try to connect dashboard when address is empty."
},
{
"name": "spring.cloud.sentinel.transport.heartbeatIntervalMs",
"type": "java.lang.String",
"description": "send heartbeat interval millisecond."
},
{
"name": "spring.cloud.sentinel.filter.order",
"type": "java.lang.Integer",
"defaultValue": "Integer.MIN_VALUE",
"description": "Sentinel filter chain order, will be set to FilterRegistrationBean."
"description": "sentinel filter chain order, will be set to FilterRegistrationBean."
},
{
"name": "spring.cloud.sentinel.filter.urlPatterns",
"type": "java.util.List",
"description": "URL pattern for Sentinel filter, default contains '/*'."
"name": "spring.cloud.sentinel.metric.fileSingleSize",
"type": "java.lang.String",
"description": "the metric file size."
},
{
"name": "spring.cloud.sentinel.metric.fileTotalCount",
"type": "java.lang.String",
"description": "the total metric file count."
},
{
"name": "spring.cloud.sentinel.servlet.blockPage",
"type": "java.lang.String",
"description": "the process page when the flow control is triggered."
},
{
"name": "spring.cloud.sentinel.flow.coldFactor",
"type": "java.lang.String",
"defaultValue": "3",
"description": "sentinel the cold factor."
}
]
}

@ -34,13 +34,14 @@ import com.alibaba.csp.sentinel.slots.block.BlockException;
/**
* @author fangjian
* @author jiashuai.xie
*/
public class SentinelAutoConfigurationTests {
private WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(SentinelAutoConfiguration.class,
SentinelWebAutoConfiguration.class, SentinelTestConfiguration.class))
.withPropertyValues("spring.cloud.sentinel.port=8888")
.withPropertyValues("spring.cloud.sentinel.transport.port=8888")
.withPropertyValues("spring.cloud.sentinel.filter.order=123")
.withPropertyValues("spring.cloud.sentinel.filter.urlPatterns=/*,/test");
@ -65,7 +66,7 @@ public class SentinelAutoConfigurationTests {
this.contextRunner.run(context -> {
SentinelProperties sentinelProperties = context
.getBean(SentinelProperties.class);
assertThat(sentinelProperties.getPort()).isEqualTo("8888");
assertThat(sentinelProperties.getTransport().getPort()).isEqualTo("8888");
assertThat(sentinelProperties.getFilter().getUrlPatterns().size())
.isEqualTo(2);
assertThat(sentinelProperties.getFilter().getUrlPatterns().get(0))

@ -1,5 +0,0 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.cloud.alibaba.storage.OSSAutoConfiguration,\
org.springframework.cloud.alibaba.storage.endpoint.OSSEndpointAutoConfiguration
org.springframework.context.ApplicationListener=\
org.springframework.cloud.alibaba.storage.OSSApplicationListener

@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-test</artifactId>
<version>0.2.0.BUILD-SNAPSHOT</version>
<version>0.2.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba</artifactId>
<version>0.2.0.BUILD-SNAPSHOT</version>
<version>0.2.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-test</artifactId>
<version>0.2.0.BUILD-SNAPSHOT</version>
<version>0.2.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

@ -5,13 +5,13 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba</artifactId>
<version>0.2.0.BUILD-SNAPSHOT</version>
<version>0.2.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-storage</artifactId>
<name>Spring Cloud Alibaba Storage Autoconfigure</name>
<artifactId>spring-cloud-alicloud-oss</artifactId>
<name>Spring Cloud Alibaba Cloud OSS</name>
<dependencies>

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.storage;
package org.springframework.cloud.alibaba.oss;
import java.util.Map;

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.storage;
package org.springframework.cloud.alibaba.oss;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -22,7 +22,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.alibaba.storage.resource.OSSStorageProtocolResolver;
import org.springframework.cloud.alibaba.oss.resource.OSSStorageProtocolResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.storage;
package org.springframework.cloud.alibaba.oss;
/**
* OSS constants

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.storage;
package org.springframework.cloud.alibaba.oss;
import java.util.Arrays;
import java.util.HashMap;

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.storage.endpoint;
package org.springframework.cloud.alibaba.oss.endpoint;
import java.util.ArrayList;
import java.util.HashMap;

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.storage.endpoint;
package org.springframework.cloud.alibaba.oss.endpoint;
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.storage.resource;
package org.springframework.cloud.alibaba.oss.resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.storage.resource;
package org.springframework.cloud.alibaba.oss.resource;
import java.io.File;
import java.io.FileNotFoundException;

@ -0,0 +1,5 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.cloud.alibaba.oss.OSSAutoConfiguration,\
org.springframework.cloud.alibaba.oss.endpoint.OSSEndpointAutoConfiguration
org.springframework.context.ApplicationListener=\
org.springframework.cloud.alibaba.oss.OSSApplicationListener

@ -14,15 +14,15 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.storage.test;
package org.springframework.cloud.alibaba.oss.test;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.cloud.alibaba.storage.OSSAutoConfiguration;
import org.springframework.cloud.alibaba.storage.OSSProperties;
import org.springframework.cloud.alibaba.oss.OSSAutoConfiguration;
import org.springframework.cloud.alibaba.oss.OSSProperties;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClient;

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.storage.test;
package org.springframework.cloud.alibaba.oss.test;
import static org.assertj.core.api.Assertions.assertThat;
@ -23,8 +23,8 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.cloud.alibaba.storage.OSSAutoConfiguration;
import org.springframework.cloud.alibaba.storage.OSSProperties;
import org.springframework.cloud.alibaba.oss.OSSAutoConfiguration;
import org.springframework.cloud.alibaba.oss.OSSProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@ -4,7 +4,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba</artifactId>
<version>0.2.0.BUILD-SNAPSHOT</version>
<version>0.2.0</version>
</parent>
<artifactId>spring-cloud-starter-alibaba</artifactId>
<packaging>pom</packaging>
@ -14,6 +14,5 @@
<module>spring-cloud-starter-alibaba-nacos-config</module>
<module>spring-cloud-starter-alibaba-nacos-discovery</module>
<module>spring-cloud-starter-alibaba-sentinel</module>
<module>spring-cloud-starter-alibaba-storage</module>
</modules>
</project>

@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba</artifactId>
<version>0.2.0.BUILD-SNAPSHOT</version>
<version>0.2.0</version>
</parent>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
<name>Spring Cloud Starter Alibaba Nacos Config</name>

@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba</artifactId>
<version>0.2.0.BUILD-SNAPSHOT</version>
<version>0.2.0</version>
</parent>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<name>Spring Cloud Starter Alibaba Nacos Discovery</name>

@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba</artifactId>
<version>0.2.0.BUILD-SNAPSHOT</version>
<version>0.2.0</version>
</parent>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
<name>Spring Cloud Starter Alibaba Sentinel</name>

@ -0,0 +1,16 @@
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba</artifactId>
<version>0.2.0</version>
</parent>
<artifactId>spring-cloud-starter-alicloud</artifactId>
<packaging>pom</packaging>
<name>Spring Cloud Alibaba Cloud Starters</name>
<description>Spring Cloud Alibaba Cloud Starters</description>
<modules>
<module>spring-cloud-starter-alicloud-oss</module>
</modules>
</project>

@ -4,16 +4,16 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba</artifactId>
<version>0.2.0.BUILD-SNAPSHOT</version>
<artifactId>spring-cloud-starter-alicloud</artifactId>
<version>0.2.0</version>
</parent>
<artifactId>spring-cloud-starter-alibaba-storage</artifactId>
<name>Spring Cloud Starter Alibaba Storage</name>
<artifactId>spring-cloud-starter-alicloud-oss</artifactId>
<name>Spring Cloud Starter Alibaba Cloud OSS</name>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-storage</artifactId>
<artifactId>spring-cloud-alicloud-oss</artifactId>
</dependency>
<dependency>
<groupId>com.aliyun.oss</groupId>
Loading…
Cancel
Save