Compare commits

...

69 Commits

Author SHA1 Message Date
liaochuntao ead0847b66
Merge pull request #99 from chuntaojun/1.x
adding default values
2019-12-17 23:02:09 +08:00
chuntaojun 1a88009ad7 refactor: adding default values 2019-12-14 15:04:50 +08:00
chuntaojun e5bb1b8c7e refactor: code specification and adding default values 2019-12-14 15:02:13 +08:00
liaochuntao e3409c7eed
Merge pull request #93 from chuntaojun/1.x
update nacos-client to 1.1.4
2019-10-29 19:38:56 +08:00
chuntaojun 1ba2491ccd fix: Repair of guava rely on version 2019-10-29 19:35:31 +08:00
chuntaojun 47671df1ad fix(config): Error repair method signature 2019-10-29 18:57:57 +08:00
chuntaojun aff2180ea9 fix(config): fix issue #81 2019-10-25 14:09:29 +08:00
chuntaojun c9427d7fbb refactor(config): Optimizing the allocation of binding code 2019-10-23 15:37:40 +08:00
chuntaojun 0f6a8baa17 fix(config): Repair to remove useless attribute logic 2019-10-21 14:52:36 +08:00
chuntaojun 250138025b style: Add code format file 2019-10-18 13:56:41 +08:00
chuntaojun 9dfa99c988 fix(config): Fix configuration error filter 2019-09-20 22:21:04 +08:00
liaochuntao 31db2c5e44
Merge pull request #82 from chuntaojun/1.x
refactor(config)
2019-09-15 08:44:58 +08:00
chuntaojun 4dded4e4b1 refactor(config): Code optimization 2019-09-15 08:41:13 +08:00
chuntaojun 0001763472 fix(config): Repair the load error log level configuration 2019-09-12 14:42:11 +08:00
liaochuntao bdc4a8ae43
Merge pull request #79 from chuntaojun/1.x
refactor(all):
2019-09-12 12:44:26 +08:00
chuntaojun 0ab2da5283 refactor(all): 2019-09-12 12:32:49 +08:00
liaochuntao 68cdf77f54
Merge pull request #78 from leshalv/1.x
⬆️ 升级 parent模块中 maven-compiler-plugin 版本为3.8.0,删除maven-source…
2019-09-12 10:34:40 +08:00
SanLi 227a3809f3 ⬆️ 升级 parent模块中 maven-compiler-plugin 版本为3.8.0,删除maven-source-plugin.version 声明,添加主项目 pom.xml properties 标签 maven-source-plugin.version 声明,指定版本为3.1.0,并优化maven-source-plugin 插件配置
#71 #72
2019-09-12 10:15:52 +08:00
liaochuntao 506f8fdc26
Merge pull request #75 from chuntaojun/fix_issue_73
feat(config): feat issue #73
2019-09-10 22:58:57 +08:00
chuntaojun 2a3497bae8 feat(config): feat issue #73 2019-09-10 22:31:53 +08:00
liaochuntao 61b5538da6
Merge pull request #69 from chuntaojun/1.x
docs(config):
2019-09-10 09:43:07 +08:00
chuntaojun c53d45d750 docs(config): 2019-09-10 09:40:20 +08:00
liaochuntao ad133c87dd
Merge pull request #68 from chuntaojun/feat_auto_deregister_1.x
feat(config、naming): Support services automatically logout and optimi…
2019-09-10 09:26:27 +08:00
chuntaojun 5146e555f7 fix(config): Repair the config module configuration pull and automatic monitoring error 2019-09-10 00:08:23 +08:00
chuntaojun 6f2c259114 fix(config): 2019-09-09 23:56:23 +08:00
chuntaojun 18e33fb098 feat(config、naming): Support services automatically logout and optimizing the config experience 2019-09-08 16:07:30 +08:00
liaochuntao 953eed2d42
Merge pull request #48 from chuntaojun/1.x
refactor: Optimize configuration information read functions
2019-08-16 12:42:15 +08:00
chuntaojun 774b308b3a refactor: Depend on the upgrade nacos-spring-project to 0.3.3 2019-08-16 12:26:07 +08:00
chuntaojun c83a201fca refactor(update version to 0.1.3): 2019-08-16 10:48:41 +08:00
chuntaojun c66547bad9 refactor(config): Optimize configuration information read functions 2019-08-13 20:02:55 +08:00
chuntaojun 4916289bcb feat(config): add ramRoleName 2019-08-12 09:09:48 +08:00
chuntaojun 1d42a4bf8c feat: 2019-08-09 17:26:23 +08:00
liaochuntao c7f9ede864
Merge pull request #45 from chuntaojun/1.x_log
feat(config): support read log setting
2019-08-06 11:58:52 +08:00
chuntaojun 02675b3167 test: fix test case bug 2019-08-06 11:52:33 +08:00
chuntaojun 333f0d7755 feat(config): support read log setting 2019-08-06 11:39:33 +08:00
liaochuntao ae79de4b97
Merge pull request #38 from chuntaojun/1.x
1.x
2019-07-25 12:14:14 +08:00
chuntaojun 3cc49b3d8e fix(config): fix NacosConfigAutoConfiguration 2019-07-25 11:45:33 +08:00
chuntaojun 7b78753758 fix(config): remove beanfactory register singleton object 2019-07-25 11:43:12 +08:00
chuntaojun 4e102e56d1 fix: 2019-07-25 11:31:40 +08:00
chuntaojun f94a675959 refactor: update version to 0.1.2 2019-07-25 11:26:39 +08:00
liaochuntao 842b0e2135
Merge pull request #33 from chuntaojun/1.x
support new feature and fix issue #18
2019-07-19 11:45:22 +08:00
chuntaojun c63c09f580 ci: 2019-07-19 11:42:20 +08:00
chuntaojun 9e91534831 ci: 2019-07-19 11:31:19 +08:00
chuntaojun 8baae0e520 ci: 2019-07-19 11:27:34 +08:00
chuntaojun 5b389c1b84 ci: 2019-07-19 11:06:26 +08:00
chuntaojun 4eeb85fc6f ci: 2019-07-19 11:02:48 +08:00
chuntaojun c5bce068fa fix(config): remove unuse package 2019-07-19 10:58:02 +08:00
chuntaojun 8b3f1a37c2 feat: 2019-07-19 10:51:43 +08:00
chuntaojun 844242b493 feat(config): support new nacos-client feature and spring-nacos-project feature 2019-07-19 10:41:12 +08:00
chuntaojun 0a9f54f215 feat: 2019-07-19 09:35:14 +08:00
fangjian0423 21972f263b fix test case for 1.x branch 2019-01-29 16:13:08 +08:00
fangjian0423 483271f2ee remove sk in healthindicator and endpoint 2019-01-16 11:39:27 +08:00
fangjian0423 77a0b1ef6d remove duplicate maven plugin 2018-12-13 20:42:39 +08:00
fangjian0423 5bfc05876a update version for 1.x branch 2018-12-13 20:32:37 +08:00
fangjian0423 050d10ab5a add conditional to NacosConfigAutoConfiguration, NacosDiscoveryAutoConfiguration for springboot 1.x 2018-09-26 21:51:35 +08:00
format c5498e440d
Update README.md 2018-09-26 19:04:51 +08:00
fangjian0423 546dd7df39 Integrate with Travis CI 2018-09-26 17:44:34 +08:00
fangjian0423 6cf028d929 Integrate with Travis CI 2018-09-26 17:41:00 +08:00
fangjian0423 83e0bc6809 update nacos spring version 2018-09-26 17:29:58 +08:00
fangjian0423 d839e5c9a6 Integrate with Travis CI 2018-09-26 17:24:34 +08:00
fangjian0423 1f7bcb2736 add nacos server detail info in health indicator 2018-09-25 15:46:19 +08:00
fangjian0423 e4c4d39f18 update samples 2018-09-25 15:17:33 +08:00
fangjian0423 4ff3b44268 modify conditional class in nacos config, discovery actuator 2018-09-25 15:17:21 +08:00
fangjian0423 8fc2b59dbe fix test case 2018-09-22 14:32:07 +08:00
fangjian0423 b84631340f Update documents 2018-09-20 11:44:08 +08:00
fangjian0423 09833490d2 Update documents 2018-09-20 11:39:55 +08:00
fangjian0423 21f9944b6f modify nacos config sample, update docs, modify endpoints 2018-09-19 16:37:20 +08:00
fangjian0423 ac97b09c18 Update documents 2018-09-18 21:23:27 +08:00
fangjian0423 a28b60f1b3 commit 1.x branch to support springboot 1.x 2018-09-18 17:36:53 +08:00
75 changed files with 3307 additions and 1549 deletions

View File

@ -6,10 +6,12 @@ notifications:
on_success: change
on_failure: always
dist: trusty
language: java
jdk:
- openjdk10
- openjdk8
- openjdk7
script:
script:

View File

@ -1,144 +0,0 @@
### Nacos Config
First, you have to start a Nacos Server in backend , If you don't know steps, you can learn about [quick start](https://nacos.io/en-us/docs/quick-start.html).
Suppose your Nacos Server is startup, you would add [`nacos-config-spring-boot-starter`](nacos-config-spring-boot-starter) in your Spring application's dependencies :
```xml
<dependencies>
...
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-config-spring-boot-starter</artifactId>
<version>${latest.version}</version>
</dependency>
...
</dependencies>
```
Note: Version [0.2.x.RELEASE](https://mvnrepository.com/artifact/com.alibaba.boot/nacos-config-spring-boot-starter) is compatible with the Spring Boot 2.x. Version [0.1.x.RELEASE](https://mvnrepository.com/artifact/com.alibaba.boot/nacos-config-spring-boot-starter) is compatible with the Spring Boot 1.x.
After that, you could define some configurations in `application.properties`:
```properties
nacos.config.server-addr=localhost:8848
```
> `nacos.config.server-addr` attribute configures "\${host}:${port}" of your Nacos Server
Then you could using `@SpringBootApplication` to annotate main class like normal SpringBoot Application and startup:
```java
@SpringBootApplication
public class ConfigApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigApplication.class, args);
}
}
```
If you'd like to use "Distributed Configuration" features, `ConfigService` is a core service interface to get or publish config, you could use "Dependency Injection" to inject `ConfigService` instance in your Spring Beans.
```java
@Service
public class ConfigServiceDemo {
@NacosInjected
private ConfigService configService;
public void demoGetConfig() {
try {
String dataId = "{dataId}";
String group = "{group}";
String content = configService.getConfig(dataId, groupId, 5000);
System.out.println(content);
} catch (NacosException e) {
e.printStackTrace();
}
}
...
}
```
above code equals below one:
```java
try {
// Initialize the configuration service, and the console automatically obtains the following parameters through the sample code.
String serverAddr = "{serverAddr}";
String dataId = "{dataId}";
String group = "{group}";
Properties properties = new Properties();
properties.put("serverAddr", serverAddr);
ConfigService configService = NacosFactory.createConfigService(properties);
// Actively get the configuration.
String content = configService.getConfig(dataId, group, 5000);
System.out.println(content);
} catch (NacosException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
```
## Endpoint
Nacos config starter support the implementation of Spring Boot actuator endpoints.
**Prerequisite:**
Adding `nacos-config-spring-boot-actuator` to your pom.xml in Nacos Config Project.
Then Configure your endpoint security strategy.
* Spring Boot1.x
```properties
management.security.enabled=false
```
* Spring Boot2.x
```properties
management.endpoints.web.exposure.include=*
```
To view the endpoint information, visit the following URLS:
* Spring Boot1.x: URL is http://127.0.0.1:10011/nacos-config.
* Spring Boot2.x: URL is http://127.0.0.1:10011/actuator/nacos-config.
## Health Checks
`nacos-config-spring-boot-actuator` support the standard Spring Boot `HealthIndicator` as a production-ready feature , which will be aggregated into Spring Boot's `Health` and exported on `HealthEndpoint` that works MVC (Spring Web MVC) if it is available.
Suppose a Spring Boot Web application did not specify `management.server.port`(SpringBoot1.x using `management.port`), you can access http://localhost:{port}/actuator/health (SpringBoot1.x visit http://localhost:{port}/health) via Web Client and will get a response with JSON format is like below :
```json
{
"status": "UP",
"details": {
"nacosConfig": {
"status": "UP"
},
"diskSpace": {
"status": "UP",
"details": {
"total": 250140434432,
"free": 52323512320,
"threshold": 10485760
}
}
}
}
```
For more information about Nacos Spring, see [Nacos Spring Project](https://github.com/nacos-group/nacos-spring-project).
## Relative Projects
* [Alibaba Nacos](https://github.com/alibaba/nacos)
* [Alibaba Spring Context Support](https://github.com/alibaba/spring-context-support)
* [Nacos Spring Project](https://github.com/nacos-group/nacos-spring-project)
* [Nacos Spring Cloud Project](https://github.com/spring-cloud-incubator/spring-cloud-alibaba)

View File

@ -1,131 +0,0 @@
### Nacos Discovery
First, you have to start a Nacos Server in backend , If you don't know steps, you can learn about [quick start](https://nacos.io/en-us/docs/quick-start.html).
Suppose your Nacos Server is startup, you would add [`nacos-discovery-spring-boot-starter`](nacos-discovery-spring-boot-starter) in your Spring application's dependencies :
```xml
<dependencies>
...
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-discovery-spring-boot-starter</artifactId>
<version>${latest.version}</version>
</dependency>
...
</dependencies>
```
Note: Version [0.2.x.RELEASE](https://mvnrepository.com/artifact/com.alibaba.boot/nacos-discovery-spring-boot-starter) is compatible with the Spring Boot 2.x. Version [0.1.x.RELEASE](https://mvnrepository.com/artifact/com.alibaba.boot/nacos-discovery-spring-boot-starter) is compatible with the Spring Boot 1.x.
After that, you could define some configurations in `application.properties`:
```properties
nacos.discovery.server-addr=localhost:8848
```
> `nacos.discovery.server-addr` attribute configures "\${host}:${port}" of your Nacos Server
Then you could using `@SpringBootApplication` to annotate main class like normal SpringBoot Application and startup:
```java
@SpringBootApplication
public class DiscoveryApplication {
public static void main(String[] args) {
SpringApplication.run(DiscoveryApplication.class, args);
}
}
```
If you'd like to use "Service Registry" features, `NamingService` is a core service interface to get or publish config, you could use "Dependency Injection" to inject `NamingService` instance in your Spring Beans.
```java
@Service
public class NamingServiceDemo {
@NacosInjected
private NamingService namingService;
public void demoRegisterService() {
try {
namingService.registerInstance("test-service", "1.1.1.1", 8080);
} catch (NacosException e) {
e.printStackTrace();
}
}
...
}
```
above code equals below one:
```java
try {
// Initialize the naming service, and the console automatically obtains the following parameters through the sample code.
String serverAddr = "{serverAddr}";
Properties properties = new Properties();
properties.put("serverAddr", serverAddr);
NamingService naming = NamingFactory.createNamingService(properties);
namingService.registerInstance("test-service", "1.1.1.1", 8080);
} catch (NacosException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
```
For more information about Nacos Spring, see [Nacos Spring Project](https://github.com/nacos-group/nacos-spring-project).
## Endpoint
Nacos discovery starter also support the implementation of Spring Boot actuator endpoints.
**Prerequisite:**
Adding `nacos-discovery-spring-boot-actuator` to your pom.xml in Nacos Discovery Project.
Then Configure your endpoint security strategy.
* Spring Boot1.x
```properties
management.security.enabled=false
```
* Spring Boot2.x
```properties
management.endpoints.web.exposure.include=*
```
To view the endpoint information, visit the following URLS:
* Spring Boot1.x: URL is http://127.0.0.1:10012/nacos-discovery.
* Spring Boot2.x: URL is http://127.0.0.1:10012/actuator/nacos-discovery.
## Health Checks
`nacos-discovery-spring-boot-actuator` support the standard Spring Boot `HealthIndicator` as a production-ready feature , which will be aggregated into Spring Boot's `Health` and exported on `HealthEndpoint` that works MVC (Spring Web MVC) if it is available.
Suppose a Spring Boot Web application did not specify `management.server.port`(SpringBoot1.x using `management.port`), you can access http://localhost:{port}/actuator/health (SpringBoot1.x visit http://localhost:{port}/health) via Web Client and will get a response with JSON format is like below :
```json
{
"status": "UP",
"details": {
"nacosDiscovery": {
"status": "UP"
},
"diskSpace": {
"status": "UP",
"details": {
"total": 250140434432,
"free": 52323680256,
"threshold": 10485760
}
}
}
}
```

244
README.md
View File

@ -32,8 +32,6 @@ Nacos Spring Boot Project consist of two parts: `nacos-config-spring-boot` and `
| -------------- | ------------- |
| Java | 1.8+ |
| Spring Boot | 2.0.3.RELEASE |
| Nacos-Spring-Context | 0.2.2-RC1 |
**1.x branch**
@ -41,16 +39,252 @@ Nacos Spring Boot Project consist of two parts: `nacos-config-spring-boot` and `
| -------------- | ------------- |
| Java | 1.7+ |
| Spring Boot | 1.4.1.RELEASE |
| Nacos-Spring-Context | 0.2.2-RC1 |
## Quick Start
### Nacos Config
- [Nacos Config Quick Start](https://github.com/nacos-group/nacos-spring-boot-project/blob/master/NACOS-CONFIG-QUICK-START.md)
First, you have to start a Nacos Server in backend , If you don't know steps, you can learn about [quick start](https://nacos.io/en-us/docs/quick-start.html).
- [Nacos Discovery Quick Start](https://github.com/nacos-group/nacos-spring-boot-project/blob/master/NACOS-DISCOVERY-QUICK-START.md)
Suppose your Nacos Server is startup, you would add [`nacos-config-spring-boot-starter`](nacos-config-spring-boot-starter) in your Spring application's dependencies :
```xml
<dependencies>
...
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-config-spring-boot-starter</artifactId>
<version>${latest.version}</version>
</dependency>
...
</dependencies>
```
After that, you could define some configurations in `application.properties`:
```properties
nacos.config.server-addr=localhost
```
> `nacos.config.server-addr` attribute configures "\${host}:${port}" of your Nacos Server
Then you could using `@SpringBootApplication` to annotate main class like normal SpringBoot Application and startup:
```java
@SpringBootApplication
public class ConfigApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigApplication.class, args);
}
}
```
If you'd like to use "Distributed Configuration" features, `ConfigService` is a core service interface to get or publish config, you could use "Dependency Injection" to inject `ConfigService` instance in your Spring Beans.
```java
@Service
public class ConfigServiceDemo {
@NacosInjected
private ConfigService configService;
public void demoGetConfig() {
try {
String dataId = "{dataId}";
String group = "{group}";
String content = configService.getConfig(dataId, groupId, 5000);
System.out.println(content);
} catch (NacosException e) {
e.printStackTrace();
}
}
...
}
```
above code equals below one:
```java
try {
// Initialize the configuration service, and the console automatically obtains the following parameters through the sample code.
String serverAddr = "{serverAddr}";
String dataId = "{dataId}";
String group = "{group}";
Properties properties = new Properties();
properties.put("serverAddr", serverAddr);
ConfigService configService = NacosFactory.createConfigService(properties);
// Actively get the configuration.
String content = configService.getConfig(dataId, group, 5000);
System.out.println(content);
} catch (NacosException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
```
### Nacos Discovery
First, you have to start a Nacos Server in backend , If you don't know steps, you can learn about [quick start](https://nacos.io/en-us/docs/quick-start.html).
Suppose your Nacos Server is startup, you would add [`nacos-discovery-spring-boot-starter`](nacos-discovery-spring-boot-starter) in your Spring application's dependencies :
```xml
<dependencies>
...
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-discovery-spring-boot-starter</artifactId>
<version>${latest.version}</version>
</dependency>
...
</dependencies>
```
After that, you could define some configurations in `application.properties`:
```properties
nacos.discovery.server-addr=localhost
```
> `nacos.discovery.server-addr` attribute configures "\${host}:${port}" of your Nacos Server
Then you could using `@SpringBootApplication` to annotate main class like normal SpringBoot Application and startup:
```java
@SpringBootApplication
public class DiscoveryApplication {
public static void main(String[] args) {
SpringApplication.run(DiscoveryApplication.class, args);
}
}
```
If you'd like to use "Service Registry" features, `NamingService` is a core service interface to get or publish config, you could use "Dependency Injection" to inject `NamingService` instance in your Spring Beans.
```java
@Service
public class NamingServiceDemo {
@NacosInjected
private NamingService namingService;
public void demoRegisterService() {
try {
namingService.registerInstance("test-service", "1.1.1.1", 8080);
} catch (NacosException e) {
e.printStackTrace();
}
}
...
}
```
above code equals below one:
```java
try {
// Initialize the naming service, and the console automatically obtains the following parameters through the sample code.
String serverAddr = "{serverAddr}";
Properties properties = new Properties();
properties.put("serverAddr", serverAddr);
NamingService naming = NamingFactory.createNamingService(properties);
namingService.registerInstance("test-service", "1.1.1.1", 8080);
} catch (NacosException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
```
For more information about Nacos Spring, see [Nacos Spring Project](https://github.com/nacos-group/nacos-spring-project).
## Endpoint
Nacos config starter and Nacos discovery starter also support the implementation of Spring Boot actuator endpoints.
**Prerequisite:**
Adding `nacos-config-spring-boot-actuator` to your pom.xml in Nacos Config Project.
Adding `nacos-discovery-spring-boot-actuator` to your pom.xml in Nacos Discovery Project.
Then Configure your endpoint security strategy.
* Spring Boot1.x
```properties
management.security.enabled=false
```
* Spring Boot2.x
```properties
management.endpoints.web.exposure.include=*
```
To view the endpoint information, visit the following URLS:
Nacos Config Project :
* Spring Boot1.x: Nacos Config Endpoint URL is http://127.0.0.1:10011/nacos-config.
* Spring Boot2.x: Nacos Config Endpoint URL is http://127.0.0.1:10011/actuator/nacos-config.
Nacos Discovery Project:
* Spring Boot1.x: Nacos Discovery Endpoint URL is http://127.0.0.1:10012/nacos-discovery.
* Spring Boot2.x: Nacos Discovery Endpoint URL is http://127.0.0.1:10012/actuator/nacos-discovery.
## Health Checks
`nacos-config-spring-boot-actuator` and `nacos-discovery-spring-boot-actuator` support the standard Spring Boot `HealthIndicator` as a production-ready feature , which will be aggregated into Spring Boot's `Health` and exported on `HealthEndpoint` that works MVC (Spring Web MVC) if it is available.
Suppose a Spring Boot Web application did not specify `management.server.port`(SpringBoot1.x using `management.port`), you can access http://localhost:{port}/actuator/health (SpringBoot1.x visit http://localhost:{port}/health) via Web Client and will get a response with JSON format is like below :
Nacos Config Project:
```json
{
"status": "UP",
"details": {
"nacosConfig": {
"status": "UP"
},
"diskSpace": {
"status": "UP",
"details": {
"total": 250140434432,
"free": 52323512320,
"threshold": 10485760
}
}
}
}
```
Nacos Discovery Project:
```json
{
"status": "UP",
"details": {
"nacosDiscovery": {
"status": "UP"
},
"diskSpace": {
"status": "UP",
"details": {
"total": 250140434432,
"free": 52323680256,
"threshold": 10485760
}
}
}
}
```
For more information about Nacos Spring, see [Nacos Spring Project](https://github.com/nacos-group/nacos-spring-project).

View File

@ -0,0 +1,296 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<profiles version="12">
<profile kind="CodeFormatterProfile" name="Spring Boot Java Conventions" version="12">
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_ellipsis" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_imports" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_javadoc_comments" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.indentation.size" value="8"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.disabling_tag" value="@formatter:off"/>
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="2"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_imports" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_package" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_binary_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.indent_root_tags" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.enabling_tag" value="@formatter:on"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column" value="false"/>
<setting id="org.eclipse.jdt.core.compiler.problem.enumIdentifier" value="error"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_block" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="90"/>
<setting id="org.eclipse.jdt.core.formatter.disabling_tag" value="@formatter:off"/>
<setting id="org.eclipse.jdt.core.formatter.use_on_off_tags" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_method_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_binary_expression" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_lambda_body" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.compact_else_if" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.compiler.problem.assertIdentifier" value="error"/>
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_binary_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_unary_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_ellipsis" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_line_comments" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.align_type_members_on_columns" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_assignment" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_conditional_expression" value="80"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while" value="insert"/>
<setting id="org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode" value="enabled"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_method_declaration" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_resources_in_try" value="80"/>
<setting id="org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column" value="false"/>
<setting id="org.eclipse.jdt.core.compiler.source" value="1.8"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="4"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_source_code" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_field" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer" value="2"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_method" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.compiler.codegen.targetPlatform" value="1.8"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_switch" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_html" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_compact_if" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.indent_empty_lines" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_unary_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_label" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_member_type" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_block_comments" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_body" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_multiple_fields" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_array_initializer" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_before_binary_operator" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch" value="do not insert"/>
<setting id="org.eclipse.jdt.core.compiler.compliance" value="1.8"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_constant" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_type_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_package" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.join_lines_in_comments" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.indent_parameter_description" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="tab"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_import_groups" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="90"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch" value="insert"/>
</profile>
</profiles>

View File

@ -0,0 +1,412 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.codeComplete.argumentPrefixes=
org.eclipse.jdt.core.codeComplete.argumentSuffixes=
org.eclipse.jdt.core.codeComplete.fieldPrefixes=
org.eclipse.jdt.core.codeComplete.fieldSuffixes=
org.eclipse.jdt.core.codeComplete.localPrefixes=
org.eclipse.jdt.core.codeComplete.localSuffixes=
org.eclipse.jdt.core.codeComplete.staticFieldPrefixes=
org.eclipse.jdt.core.codeComplete.staticFieldSuffixes=
org.eclipse.jdt.core.codeComplete.staticFinalFieldPrefixes=
org.eclipse.jdt.core.codeComplete.staticFinalFieldSuffixes=
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.doc.comment.support=enabled
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
org.eclipse.jdt.core.compiler.problem.deadCode=warning
org.eclipse.jdt.core.compiler.problem.deprecation=warning
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore
org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning
org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled
org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=disabled
org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled
org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=default
org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore
org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public
org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=all_standard_tags
org.eclipse.jdt.core.compiler.problem.missingJavadocTags=warning
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsMethodTypeParameters=disabled
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=default
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=ignore
org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
org.eclipse.jdt.core.compiler.problem.nullReference=ignore
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore
org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
org.eclipse.jdt.core.compiler.problem.unusedImport=warning
org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore
org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.processAnnotations=disabled
org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines=2147483647
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_assignment=0
org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16
org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=16
org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header=0
org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0
org.eclipse.jdt.core.formatter.alignment_for_module_statements=16
org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references=0
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80
org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16
org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_type_arguments=0
org.eclipse.jdt.core.formatter.alignment_for_type_parameters=0
org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16
org.eclipse.jdt.core.formatter.blank_lines_after_imports=1
org.eclipse.jdt.core.formatter.blank_lines_after_package=1
org.eclipse.jdt.core.formatter.blank_lines_before_field=0
org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0
org.eclipse.jdt.core.formatter.blank_lines_before_imports=1
org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1
org.eclipse.jdt.core.formatter.blank_lines_before_method=1
org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1
org.eclipse.jdt.core.formatter.blank_lines_before_package=0
org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1
org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1
org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_lambda_body=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line
org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false
org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false
org.eclipse.jdt.core.formatter.comment.count_line_length_from_starting_position=false
org.eclipse.jdt.core.formatter.comment.format_block_comments=true
org.eclipse.jdt.core.formatter.comment.format_header=false
org.eclipse.jdt.core.formatter.comment.format_html=true
org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true
org.eclipse.jdt.core.formatter.comment.format_line_comments=true
org.eclipse.jdt.core.formatter.comment.format_source_code=false
org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true
org.eclipse.jdt.core.formatter.comment.indent_root_tags=false
org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=do not insert
org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=do not insert
org.eclipse.jdt.core.formatter.comment.line_length=90
org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true
org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true
org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments=false
org.eclipse.jdt.core.formatter.compact_else_if=true
org.eclipse.jdt.core.formatter.continuation_indentation=2
org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2
org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off
org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on
org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false
org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true
org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true
org.eclipse.jdt.core.formatter.indent_empty_lines=false
org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true
org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false
org.eclipse.jdt.core.formatter.indentation.size=4
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_enum_constant=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=insert
org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=insert
org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=insert
org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert
org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert
org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert
org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert
org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert
org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow=insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert
org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert
org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources=insert
org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert
org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert
org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert
org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert
org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert
org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert
org.eclipse.jdt.core.formatter.join_lines_in_comments=true
org.eclipse.jdt.core.formatter.join_wrapped_lines=true
org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false
org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false
org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false
org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false
org.eclipse.jdt.core.formatter.lineSplit=90
org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false
org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false
org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0
org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
org.eclipse.jdt.core.formatter.parentheses_positions_in_annotation=common_lines
org.eclipse.jdt.core.formatter.parentheses_positions_in_catch_clause=common_lines
org.eclipse.jdt.core.formatter.parentheses_positions_in_enum_constant_declaration=common_lines
org.eclipse.jdt.core.formatter.parentheses_positions_in_for_statment=common_lines
org.eclipse.jdt.core.formatter.parentheses_positions_in_if_while_statement=common_lines
org.eclipse.jdt.core.formatter.parentheses_positions_in_lambda_declaration=common_lines
org.eclipse.jdt.core.formatter.parentheses_positions_in_method_delcaration=common_lines
org.eclipse.jdt.core.formatter.parentheses_positions_in_method_invocation=common_lines
org.eclipse.jdt.core.formatter.parentheses_positions_in_switch_statement=common_lines
org.eclipse.jdt.core.formatter.parentheses_positions_in_try_clause=common_lines
org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
org.eclipse.jdt.core.formatter.tabulation.char=tab
org.eclipse.jdt.core.formatter.tabulation.size=4
org.eclipse.jdt.core.formatter.use_on_off_tags=true
org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false
org.eclipse.jdt.core.formatter.wrap_before_assignment_operator=false
org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true
org.eclipse.jdt.core.formatter.wrap_before_conditional_operator=true
org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true
org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true
org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter

File diff suppressed because one or more lines are too long

View File

@ -18,7 +18,7 @@
<parent>
<artifactId>nacos-spring-boot-parent</artifactId>
<groupId>com.alibaba.boot</groupId>
<version>0.9.0</version>
<version>0.1.4</version>
<relativePath>../nacos-spring-boot-parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -16,14 +16,16 @@
*/
package com.alibaba.boot.nacos.actuate.autoconfigure;
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import com.alibaba.boot.nacos.actuate.endpoint.NacosConfigEndpoint;
import com.alibaba.boot.nacos.config.NacosConfigConstants;
import org.springframework.boot.actuate.condition.ConditionalOnEnabledEndpoint;
import org.springframework.boot.actuate.endpoint.Endpoint;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.alibaba.boot.nacos.actuate.endpoint.NacosConfigEndpoint;
/**
* Nacos Config {@link Endpoint} Auto-{@link Configuration}
*
@ -31,11 +33,12 @@ import com.alibaba.boot.nacos.actuate.endpoint.NacosConfigEndpoint;
* @see Endpoint
*/
@Configuration
@ConditionalOnClass(Endpoint.class)
public class NacosConfigEndpointAutoConfiguration {
@Bean
@ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint
@ConditionalOnEnabledEndpoint(NacosConfigConstants.ENDPOINT_PREFIX)
public NacosConfigEndpoint nacosEndpoint() {
return new NacosConfigEndpoint();
}

View File

@ -16,8 +16,12 @@
*/
package com.alibaba.boot.nacos.actuate.autoconfigure;
import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
import com.alibaba.boot.nacos.actuate.health.NacosConfigHealthIndicator;
import com.alibaba.boot.nacos.config.NacosConfigConstants;
import com.alibaba.boot.nacos.config.autoconfigure.NacosConfigAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.ConditionalOnEnabledHealthIndicator;
import org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
@ -26,10 +30,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.alibaba.boot.nacos.actuate.health.NacosConfigHealthIndicator;
import com.alibaba.boot.nacos.config.NacosConfigConstants;
import com.alibaba.boot.nacos.config.autoconfigure.NacosConfigAutoConfiguration;
/**
* Nacos {@link NacosConfigHealthIndicator} Auto Configuration
*

View File

@ -16,24 +16,11 @@
*/
package com.alibaba.boot.nacos.actuate.endpoint;
import static com.alibaba.nacos.spring.util.NacosBeanUtils.CONFIG_GLOBAL_NACOS_PROPERTIES_BEAN_NAME;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.apache.commons.lang3.ClassUtils;
import org.apache.commons.lang3.StringUtils;
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.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.type.AnnotationMetadata;
import org.w3c.dom.Element;
import com.alibaba.boot.nacos.common.PropertiesUtils;
import com.alibaba.boot.nacos.config.NacosConfigConstants;
import com.alibaba.fastjson.JSONObject;
@ -41,6 +28,19 @@ import com.alibaba.nacos.api.config.annotation.NacosConfigListener;
import com.alibaba.nacos.api.config.annotation.NacosConfigurationProperties;
import com.alibaba.nacos.spring.context.event.config.NacosConfigMetadataEvent;
import com.alibaba.nacos.spring.util.NacosUtils;
import org.apache.commons.lang3.ClassUtils;
import org.apache.commons.lang3.StringUtils;
import org.w3c.dom.Element;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
import org.springframework.boot.actuate.endpoint.Endpoint;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.type.AnnotationMetadata;
import static com.alibaba.nacos.spring.util.NacosBeanUtils.CONFIG_GLOBAL_NACOS_PROPERTIES_BEAN_NAME;
/**
* Actuator {@link Endpoint} to expose Nacos Config Meta Data
@ -48,8 +48,7 @@ import com.alibaba.nacos.spring.util.NacosUtils;
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
* @see Endpoint
*/
@Endpoint(id = NacosConfigConstants.ENDPOINT_PREFIX)
public class NacosConfigEndpoint
public class NacosConfigEndpoint extends AbstractEndpoint<Map<String, Object>>
implements ApplicationListener<NacosConfigMetadataEvent> {
@Autowired
@ -57,9 +56,13 @@ public class NacosConfigEndpoint
private Map<String, JSONObject> nacosConfigMetadataMap = new HashMap<>();
@ReadOperation
public NacosConfigEndpoint() {
super(NacosConfigConstants.ENDPOINT_PREFIX);
}
@Override
public Map<String, Object> invoke() {
Map<String, Object> result = new HashMap<>();
Map<String, Object> result = new HashMap<>(8);
if (!(ClassUtils.isAssignable(applicationContext.getEnvironment().getClass(),
ConfigurableEnvironment.class))) {

View File

@ -18,12 +18,6 @@ package com.alibaba.boot.nacos.actuate.health;
import java.util.Properties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.context.ApplicationContext;
import com.alibaba.boot.nacos.common.PropertiesUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.api.config.ConfigService;
@ -31,6 +25,12 @@ import com.alibaba.nacos.spring.factory.CacheableEventPublishingNacosServiceFact
import com.alibaba.nacos.spring.factory.NacosServiceFactory;
import com.alibaba.nacos.spring.metadata.NacosServiceMetaData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.context.ApplicationContext;
/**
* Nacos Config {@link HealthIndicator}
*
@ -46,7 +46,8 @@ public class NacosConfigHealthIndicator extends AbstractHealthIndicator {
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
builder.up();
NacosServiceFactory nacosServiceFactory = CacheableEventPublishingNacosServiceFactory.getSingleton();
NacosServiceFactory nacosServiceFactory = CacheableEventPublishingNacosServiceFactory
.getSingleton();
for (ConfigService configService : nacosServiceFactory.getConfigServices()) {
if (configService instanceof NacosServiceMetaData) {
NacosServiceMetaData nacosServiceMetaData = (NacosServiceMetaData) configService;

View File

@ -18,15 +18,15 @@ package com.alibaba.boot.nacos.actuate.endpoint;
import java.util.Map;
import com.alibaba.boot.nacos.config.autoconfigure.NacosConfigAutoConfiguration;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import com.alibaba.boot.nacos.config.autoconfigure.NacosConfigAutoConfiguration;
/**
* {@link NacosConfigEndpoint} Test
*

View File

@ -18,7 +18,7 @@
<parent>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-spring-boot-parent</artifactId>
<version>0.9.0</version>
<version>0.1.4</version>
<relativePath>../nacos-spring-boot-parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -25,12 +25,14 @@ import com.alibaba.nacos.spring.context.annotation.config.EnableNacosConfig;
*/
public interface NacosConfigConstants {
String ENDPOINT_PREFIX = "nacos-config";
String ENDPOINT_PREFIX = "nacos_config";
String ENABLED = EnableNacosConfig.CONFIG_PREFIX + "enabled";
String PREFIX = "nacos.config";
String PREFIX = "nacos.config";
String NACOS_BOOTSTRAP = PREFIX + ".bootstrap.enable";
String NACOS_LOG_BOOTSTRAP = PREFIX + ".bootstrap.log.enable";
}

View File

@ -14,32 +14,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.boot.nacos.config.util.editor;
import java.beans.PropertyEditorSupport;
package com.alibaba.boot.nacos.config.autoconfigure;
/**
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
* @since
* @since 0.1.3
*/
public class NacosCharSequenceEditor extends PropertyEditorSupport {
public class NacosBootConfigException extends RuntimeException {
@Override
public void setValue(Object value) {
if (value == null) {
super.setValue("");
}
if (value instanceof CharSequence) {
CharSequence sequence = (CharSequence) value;
super.setValue(sequence.toString());
} else {
super.setValue(value);
}
}
public NacosBootConfigException(Throwable cause) {
super(cause);
}
@Override
public String getAsText() {
Object value = getValue();
return String.valueOf(value);
}
}
public NacosBootConfigException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@ -1,120 +0,0 @@
/*
* 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.boot.nacos.config.autoconfigure;
import com.alibaba.boot.nacos.config.NacosConfigConstants;
import com.alibaba.boot.nacos.config.properties.NacosConfigProperties;
import com.alibaba.boot.nacos.config.util.NacosConfigPropertiesUtils;
import com.alibaba.boot.nacos.config.util.NacosPropertiesBuilder;
import com.alibaba.nacos.api.config.ConfigType;
import com.alibaba.nacos.spring.core.env.NacosPropertySource;
import com.alibaba.nacos.spring.core.env.NacosPropertySourcePostProcessor;
import com.alibaba.nacos.spring.factory.CacheableEventPublishingNacosServiceFactory;
import com.alibaba.nacos.spring.util.config.NacosConfigLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.util.StringUtils;
import java.util.Properties;
import static com.alibaba.nacos.spring.util.NacosUtils.buildDefaultPropertySourceName;
/**
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
* @since
*/
public class NacosConfigApplicationContextInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
private final Logger logger = LoggerFactory.getLogger(NacosConfigApplicationContextInitializer.class);
private ConfigurableEnvironment environment;
private NacosConfigProperties nacosConfigProperties;
private NacosConfigLoader nacosConfigLoader;
@Override
public void initialize(ConfigurableApplicationContext context) {
CacheableEventPublishingNacosServiceFactory singleton = CacheableEventPublishingNacosServiceFactory.getSingleton();
singleton.setApplicationContext(context);
environment = context.getEnvironment();
nacosConfigLoader = new NacosConfigLoader(environment);
nacosConfigLoader.setNacosServiceFactory(singleton);
if (!isEnable()) {
logger.info("[Nacos Config Boot] : The preload configuration is not enabled");
} else {
nacosConfigProperties = NacosConfigPropertiesUtils.buildNacosConfigProperties(environment);
Properties globalProperties = buildGlobalNacosProperties();
MutablePropertySources mutablePropertySources = environment.getPropertySources();
mutablePropertySources.addLast(reqGlobalNacosConfig(globalProperties, nacosConfigProperties.getType()));
for (NacosConfigProperties.Config config : nacosConfigProperties.getExtConfig()) {
mutablePropertySources.addLast(reqSubNacosConfig(config, globalProperties, config.getType()));
}
}
}
private boolean isEnable() {
return Boolean.valueOf(environment.getProperty(NacosConfigConstants.NACOS_BOOTSTRAP, "false"));
}
private Properties buildGlobalNacosProperties() {
return NacosPropertiesBuilder.buildNacosProperties(nacosConfigProperties.getServerAddr(), nacosConfigProperties.getNamespace(),
nacosConfigProperties.getEndpoint(), nacosConfigProperties.getSecretKey(), nacosConfigProperties.getAccessKey(),
nacosConfigProperties.getConfigLongPollTimeout(), nacosConfigProperties.getConfigRetryTime(),
nacosConfigProperties.getMaxRetry(), nacosConfigProperties.isEnableRemoteSyncConfig());
}
private Properties buildSubNacosProperties(Properties globalProperties, NacosConfigProperties.Config config) {
if (StringUtils.isEmpty(config.getServerAddr())) {
return globalProperties;
}
Properties sub = NacosPropertiesBuilder.buildNacosProperties(config.getServerAddr(), config.getNamespace(),
config.getEndpoint(), config.getSecretKey(), config.getAccessKey(), config.getConfigLongPollTimeout(),
config.getConfigRetryTime(), config.getMaxRetry(), config.isEnableRemoteSyncConfig());
NacosPropertiesBuilder.merge(sub, globalProperties);
return sub;
}
private NacosPropertySource reqGlobalNacosConfig(Properties globalProperties, ConfigType type) {
NacosPropertySource propertySource = reqNacosConfig(globalProperties, nacosConfigProperties.getDataId(), nacosConfigProperties.getGroup(), type);
propertySource.setAutoRefreshed(nacosConfigProperties.isAutoRefresh());
NacosPropertySourcePostProcessor.addListenerIfAutoRefreshed(propertySource, globalProperties, environment);
return propertySource;
}
private NacosPropertySource reqSubNacosConfig(NacosConfigProperties.Config config, Properties globalProperties, ConfigType type) {
Properties subConfigProperties = buildSubNacosProperties(globalProperties, config);
NacosPropertySource nacosPropertySource = reqNacosConfig(subConfigProperties, config.getDataId(), config.getGroup(), type);
nacosPropertySource.setAutoRefreshed(config.isAutoRefresh());
NacosPropertySourcePostProcessor.addListenerIfAutoRefreshed(nacosPropertySource, subConfigProperties, environment);
return nacosPropertySource;
}
private NacosPropertySource reqNacosConfig(Properties configProperties, String dataId, String groupId, ConfigType type) {
NacosPropertySource nacosPropertySource;
String config = nacosConfigLoader.load(dataId, groupId, configProperties);
nacosPropertySource = new NacosPropertySource(dataId, groupId, buildDefaultPropertySourceName(dataId, groupId, configProperties), config, type.getType());
nacosPropertySource.setDataId(dataId);
nacosPropertySource.setType(type.getType());
nacosPropertySource.setGroupId(groupId);
return nacosPropertySource;
}
}

View File

@ -0,0 +1,99 @@
/*
* 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.boot.nacos.config.autoconfigure;
import java.util.Properties;
import com.alibaba.boot.nacos.config.properties.NacosConfigProperties;
import com.alibaba.boot.nacos.config.util.Function;
import com.alibaba.boot.nacos.config.util.NacosConfigPropertiesUtils;
import com.alibaba.boot.nacos.config.util.NacosConfigUtils;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.spring.factory.CacheableEventPublishingNacosServiceFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
/**
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
* @since 0.1.2
*/
public class NacosConfigApplicationInitializer
implements ApplicationContextInitializer<ConfigurableApplicationContext> {
private final Logger logger = LoggerFactory
.getLogger(NacosConfigApplicationInitializer.class);
private ConfigurableEnvironment environment;
private final NacosConfigEnvironmentProcessor processor;
private NacosConfigProperties nacosConfigProperties;
public NacosConfigApplicationInitializer(
NacosConfigEnvironmentProcessor configEnvironmentProcessor) {
this.processor = configEnvironmentProcessor;
}
@Override
public void initialize(ConfigurableApplicationContext context) {
final CacheableEventPublishingNacosServiceFactory singleton = CacheableEventPublishingNacosServiceFactory
.getSingleton();
singleton.setApplicationContext(context);
environment = context.getEnvironment();
nacosConfigProperties = NacosConfigPropertiesUtils
.buildNacosConfigProperties(environment);
processor.publishDeferService(context);
if (!enable()) {
logger.info("[Nacos Config Boot] : The preload configuration is not enabled");
}
else {
final Function<Properties, ConfigService> builder = new Function<Properties, ConfigService>() {
@Override
public ConfigService apply(Properties input) {
try {
return singleton.createConfigService(input);
}
catch (NacosException e) {
throw new NacosBootConfigException(
"ConfigService can't be created with properties : "
+ input,
e);
}
}
};
final NacosConfigUtils configUtils = new NacosConfigUtils(
nacosConfigProperties, environment, builder);
if (processor.enable()) {
configUtils
.addListenerIfAutoRefreshed(processor.getDeferPropertySources());
}
else {
configUtils.loadConfig();
configUtils.addListenerIfAutoRefreshed();
}
}
}
private boolean enable() {
return nacosConfigProperties.getBootstrap().isEnable();
}
}

View File

@ -16,19 +16,19 @@
*/
package com.alibaba.boot.nacos.config.autoconfigure;
import static com.alibaba.nacos.spring.util.NacosBeanUtils.CONFIG_GLOBAL_NACOS_PROPERTIES_BEAN_NAME;
import com.alibaba.boot.nacos.config.NacosConfigConstants;
import com.alibaba.boot.nacos.config.properties.NacosConfigProperties;
import com.alibaba.nacos.spring.context.annotation.config.EnableNacosConfig;
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.context.annotation.Configuration;
import com.alibaba.boot.nacos.config.NacosConfigConstants;
import com.alibaba.boot.nacos.config.properties.NacosConfigProperties;
import com.alibaba.nacos.spring.context.annotation.config.EnableNacosConfig;
import org.springframework.context.annotation.Import;
import static com.alibaba.nacos.spring.util.NacosBeanUtils.CONFIG_GLOBAL_NACOS_PROPERTIES_BEAN_NAME;
/**
* Nacos Config Auto {@link Configuration}
*
@ -36,10 +36,10 @@ import org.springframework.context.annotation.Import;
*/
@ConditionalOnProperty(name = NacosConfigConstants.ENABLED, matchIfMissing = true)
@ConditionalOnMissingBean(name = CONFIG_GLOBAL_NACOS_PROPERTIES_BEAN_NAME)
@EnableConfigurationProperties(value = NacosConfigProperties.class)
@ConditionalOnClass(name = "org.springframework.boot.context.properties.bind.Binder")
@Import(value = {NacosConfigBootBeanDefinitionRegistrar.class})
@EnableNacosConfig
@EnableConfigurationProperties(value = NacosConfigProperties.class)
@ConditionalOnClass(name = "org.springframework.boot.bind.RelaxedDataBinder")
@Import(value = { NacosConfigBootBeanDefinitionRegistrar.class })
public class NacosConfigAutoConfiguration {
}

View File

@ -17,6 +17,7 @@
package com.alibaba.boot.nacos.config.autoconfigure;
import com.alibaba.boot.nacos.config.binder.NacosBootConfigurationPropertiesBinder;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
@ -29,21 +30,25 @@ import org.springframework.core.type.AnnotationMetadata;
/**
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
* @since
* @since 0.1.2
*/
@Configuration
public class NacosConfigBootBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar, BeanFactoryAware {
public class NacosConfigBootBeanDefinitionRegistrar
implements ImportBeanDefinitionRegistrar, BeanFactoryAware {
@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) beanFactory;
BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder
.rootBeanDefinition(NacosBootConfigurationPropertiesBinder.class);
defaultListableBeanFactory.registerBeanDefinition(NacosBootConfigurationPropertiesBinder.BEAN_NAME, beanDefinitionBuilder.getBeanDefinition());
}
@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) beanFactory;
BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder
.rootBeanDefinition(NacosBootConfigurationPropertiesBinder.class);
defaultListableBeanFactory.registerBeanDefinition(
NacosBootConfigurationPropertiesBinder.BEAN_NAME,
beanDefinitionBuilder.getBeanDefinition());
}
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
BeanDefinitionRegistry registry) {
}
}
}
}

View File

@ -0,0 +1,124 @@
/*
* 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.boot.nacos.config.autoconfigure;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Properties;
import com.alibaba.boot.nacos.config.properties.NacosConfigProperties;
import com.alibaba.boot.nacos.config.util.Function;
import com.alibaba.boot.nacos.config.util.NacosConfigPropertiesUtils;
import com.alibaba.boot.nacos.config.util.NacosConfigUtils;
import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.spring.factory.CacheableEventPublishingNacosServiceFactory;
import com.alibaba.nacos.spring.util.NacosUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment;
/**
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
* @since 0.1.3
*/
public class NacosConfigEnvironmentProcessor
implements EnvironmentPostProcessor, Ordered {
private final Logger logger = LoggerFactory
.getLogger(NacosConfigEnvironmentProcessor.class);
private final CacheableEventPublishingNacosServiceFactory nacosServiceFactory = CacheableEventPublishingNacosServiceFactory
.getSingleton();
private final LinkedList<NacosConfigUtils.DeferNacosPropertySource> deferPropertySources = new LinkedList<>();
private final Map<String, ConfigService> serviceCache = new HashMap<>(8);
private NacosConfigProperties nacosConfigProperties;
private final Function<Properties, ConfigService> builder = new Function<Properties, ConfigService>() {
@Override
public ConfigService apply(Properties input) {
try {
final String key = NacosUtils.identify(input);
ConfigService service = serviceCache.get(key);
if (service != null) {
return serviceCache.get(key);
}
service = NacosFactory.createConfigService(input);
serviceCache.put(key, service);
return nacosServiceFactory.deferCreateService(service, input);
}
catch (NacosException e) {
throw new NacosBootConfigException(
"ConfigService can't be created with properties : " + input, e);
}
}
};
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment,
SpringApplication application) {
application.addInitializers(new NacosConfigApplicationInitializer(this));
nacosConfigProperties = NacosConfigPropertiesUtils
.buildNacosConfigProperties(environment);
if (enable()) {
System.out.println(
"[Nacos Config Boot] : The preload log configuration is enabled");
loadConfig(environment);
}
}
private void loadConfig(ConfigurableEnvironment environment) {
final NacosConfigUtils configUtils = new NacosConfigUtils(nacosConfigProperties,
environment, builder);
configUtils.loadConfig();
// set defer nacosPropertySource
deferPropertySources.addAll(configUtils.getNacosPropertySources());
}
boolean enable() {
return nacosConfigProperties != null
&& nacosConfigProperties.getBootstrap().isLogEnable();
}
LinkedList<NacosConfigUtils.DeferNacosPropertySource> getDeferPropertySources() {
return deferPropertySources;
}
void publishDeferService(ApplicationContext context) {
try {
nacosServiceFactory.publishDeferService(context);
serviceCache.clear();
}
catch (Exception e) {
logger.error("publish defer ConfigService has some error : {}", e);
}
}
@Override
public int getOrder() {
return Ordered.LOWEST_PRECEDENCE;
}
}

View File

@ -16,64 +16,46 @@
*/
package com.alibaba.boot.nacos.config.binder;
import java.util.Properties;
import com.alibaba.boot.nacos.config.util.BinderUtils;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.config.ConfigType;
import com.alibaba.nacos.api.config.annotation.NacosConfigurationProperties;
import com.alibaba.nacos.spring.context.properties.config.NacosConfigurationPropertiesBinder;
import com.alibaba.nacos.spring.core.env.NacosPropertySource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata;
import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.ResolvableType;
import java.lang.reflect.Method;
import org.springframework.context.ConfigurableApplicationContext;
import static com.alibaba.nacos.spring.util.NacosUtils.toProperties;
/**
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
* @since
* @since 0.1.2
*/
public class NacosBootConfigurationPropertiesBinder extends NacosConfigurationPropertiesBinder {
public class NacosBootConfigurationPropertiesBinder
extends NacosConfigurationPropertiesBinder {
private final Logger logger = LoggerFactory.getLogger(NacosBootConfigurationPropertiesBinder.class);
private final Logger logger = LoggerFactory
.getLogger(NacosBootConfigurationPropertiesBinder.class);
private ConfigurableApplicationContext context;
private ConfigurationBeanFactoryMetadata beanFactoryMetadata;
private ConfigurableApplicationContext context;
public NacosBootConfigurationPropertiesBinder(ConfigurableApplicationContext applicationContext) {
super(applicationContext);
this.context = applicationContext;
this.beanFactoryMetadata = applicationContext.getBean(
ConfigurationBeanFactoryMetadata.BEAN_NAME,
ConfigurationBeanFactoryMetadata.class);
}
public NacosBootConfigurationPropertiesBinder(
ConfigurableApplicationContext applicationContext) {
super(applicationContext);
this.context = applicationContext;
}
@Override
protected void doBind(Object bean, String beanName, String dataId, String groupId,
NacosConfigurationProperties properties, String content, ConfigService configService) {
String name = "nacos-bootstrap-" + beanName;
String configType = properties.yaml() ? ConfigType.YAML.getType() : properties.type().getType();
NacosPropertySource propertySource = new NacosPropertySource(name, dataId, groupId, content, configType);
context.getEnvironment().getPropertySources().addLast(propertySource);
Binder binder = Binder.get(context.getEnvironment());
ResolvableType type = getBeanType(bean, beanName);
Bindable<?> target = Bindable.of(type).withExistingValue(bean);
binder.bind(properties.prefix(), target);
publishBoundEvent(bean, beanName, dataId, groupId, properties, content, configService);
publishMetadataEvent(bean, beanName, dataId, groupId, properties);
context.getEnvironment().getPropertySources().remove(name);
}
private ResolvableType getBeanType(Object bean, String beanName) {
Method factoryMethod = this.beanFactoryMetadata.findFactoryMethod(beanName);
if (factoryMethod != null) {
return ResolvableType.forMethodReturnType(factoryMethod);
}
return ResolvableType.forClass(bean.getClass());
}
@Override
protected void doBind(Object bean, String beanName, String dataId, String groupId,
String configType, NacosConfigurationProperties properties, String content,
ConfigService configService) {
Properties prop = toProperties(dataId, groupId, content, configType);
BinderUtils.bind(bean, properties.prefix(), prop);
publishBoundEvent(bean, beanName, dataId, groupId, properties, content,
configService);
publishMetadataEvent(bean, beanName, dataId, groupId, properties);
}
}

View File

@ -16,15 +16,17 @@
package com.alibaba.boot.nacos.config.properties;
import java.util.ArrayList;
import java.util.List;
import com.alibaba.boot.nacos.config.NacosConfigConstants;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.config.ConfigType;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.Assert;
import java.util.ArrayList;
import java.util.List;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.util.Assert;
/**
* {@link ConfigurationProperties} for configuring Nacos Config.
@ -34,298 +36,372 @@ import java.util.List;
@ConfigurationProperties(NacosConfigConstants.PREFIX)
public class NacosConfigProperties {
private String serverAddr;
private String serverAddr = "127.0.0.1:8848";
private String contextPath;
private String contextPath;
private String encode;
private String encode;
private String endpoint;
private String endpoint;
private String namespace;
private String namespace;
private String accessKey;
private String accessKey;
private String secretKey;
private String secretKey;
private boolean autoRefresh = false;
private String ramRoleName;
private String dataId;
private boolean autoRefresh = false;
private String group = Constants.DEFAULT_GROUP;
private String dataId;
private ConfigType type;
private String dataIds;
private String maxRetry;
private String group = Constants.DEFAULT_GROUP;
private String configLongPollTimeout;
private ConfigType type;
private String configRetryTime;
private String maxRetry;
private boolean enableRemoteSyncConfig = false;
private String configLongPollTimeout;
@JSONField(serialize = false)
private List<Config> extConfig = new ArrayList<>();
private String configRetryTime;
public String getServerAddr() {
return serverAddr;
}
private boolean enableRemoteSyncConfig = false;
public void setServerAddr(String serverAddr) {
Assert.notNull(serverAddr, "nacos config server-addr must not be null");
this.serverAddr = serverAddr;
}
@JSONField(serialize = false)
private List<Config> extConfig = new ArrayList<>();
public String getContextPath() {
return contextPath;
}
@NestedConfigurationProperty
private Bootstrap bootstrap = new Bootstrap();
public void setContextPath(String contextPath) {
this.contextPath = contextPath;
}
public String getServerAddr() {
return serverAddr;
}
public String getEncode() {
return encode;
}
public void setServerAddr(String serverAddr) {
Assert.notNull(serverAddr, "nacos config server-addr must not be null");
this.serverAddr = serverAddr;
}
public void setEncode(String encode) {
this.encode = encode;
}
public String getContextPath() {
return contextPath;
}
public String getEndpoint() {
return endpoint;
}
public void setContextPath(String contextPath) {
this.contextPath = contextPath;
}
public void setEndpoint(String endpoint) {
this.endpoint = endpoint;
}
public String getEncode() {
return encode;
}
public String getNamespace() {
return namespace;
}
public void setEncode(String encode) {
this.encode = encode;
}
public void setNamespace(String namespace) {
this.namespace = namespace;
}
public String getEndpoint() {
return endpoint;
}
public String getAccessKey() {
return accessKey;
}
public void setEndpoint(String endpoint) {
this.endpoint = endpoint;
}
public void setAccessKey(String accessKey) {
this.accessKey = accessKey;
}
public String getNamespace() {
return namespace;
}
public String getSecretKey() {
return secretKey;
}
public void setNamespace(String namespace) {
this.namespace = namespace;
}
public void setSecretKey(String secretKey) {
this.secretKey = secretKey;
}
public String getAccessKey() {
return accessKey;
}
public boolean isAutoRefresh() {
return autoRefresh;
}
public void setAccessKey(String accessKey) {
this.accessKey = accessKey;
}
public void setAutoRefresh(boolean autoRefresh) {
this.autoRefresh = autoRefresh;
}
public String getSecretKey() {
return secretKey;
}
public String getDataId() {
return dataId;
}
public void setSecretKey(String secretKey) {
this.secretKey = secretKey;
}
public void setDataId(String dataId) {
this.dataId = dataId;
}
public String getRamRoleName() {
return ramRoleName;
}
public String getGroup() {
return group;
}
public void setRamRoleName(String ramRoleName) {
this.ramRoleName = ramRoleName;
}
public void setGroup(String group) {
this.group = group;
}
public boolean isAutoRefresh() {
return autoRefresh;
}
public ConfigType getType() {
return type;
}
public void setAutoRefresh(boolean autoRefresh) {
this.autoRefresh = autoRefresh;
}
public void setType(ConfigType type) {
this.type = type;
}
public String getDataId() {
return dataId;
}
public String getMaxRetry() {
return maxRetry;
}
public void setDataId(String dataId) {
this.dataId = dataId;
}
public void setMaxRetry(String maxRetry) {
this.maxRetry = maxRetry;
}
public String getDataIds() {
return dataIds;
}
public String getConfigLongPollTimeout() {
return configLongPollTimeout;
}
public void setDataIds(String dataIds) {
this.dataIds = dataIds;
}
public void setConfigLongPollTimeout(String configLongPollTimeout) {
this.configLongPollTimeout = configLongPollTimeout;
}
public String getGroup() {
return group;
}
public String getConfigRetryTime() {
return configRetryTime;
}
public void setGroup(String group) {
this.group = group;
}
public void setConfigRetryTime(String configRetryTime) {
this.configRetryTime = configRetryTime;
}
public ConfigType getType() {
return type;
}
public boolean isEnableRemoteSyncConfig() {
return enableRemoteSyncConfig;
}
public void setType(ConfigType type) {
this.type = type;
}
public void setEnableRemoteSyncConfig(boolean enableRemoteSyncConfig) {
this.enableRemoteSyncConfig = enableRemoteSyncConfig;
}
public String getMaxRetry() {
return maxRetry;
}
public List<Config> getExtConfig() {
return extConfig;
}
public void setMaxRetry(String maxRetry) {
this.maxRetry = maxRetry;
}
public void setExtConfig(List<Config> extConfig) {
this.extConfig = extConfig;
}
public String getConfigLongPollTimeout() {
return configLongPollTimeout;
}
public static class Config {
public void setConfigLongPollTimeout(String configLongPollTimeout) {
this.configLongPollTimeout = configLongPollTimeout;
}
private String serverAddr;
public String getConfigRetryTime() {
return configRetryTime;
}
private String endpoint;
public void setConfigRetryTime(String configRetryTime) {
this.configRetryTime = configRetryTime;
}
private String namespace;
public boolean isEnableRemoteSyncConfig() {
return enableRemoteSyncConfig;
}
private String accessKey;
public void setEnableRemoteSyncConfig(boolean enableRemoteSyncConfig) {
this.enableRemoteSyncConfig = enableRemoteSyncConfig;
}
private String secretKey;
public List<Config> getExtConfig() {
return extConfig;
}
private String dataId;
public void setExtConfig(List<Config> extConfig) {
this.extConfig = extConfig;
}
private String group = Constants.DEFAULT_GROUP;
public Bootstrap getBootstrap() {
return bootstrap;
}
private ConfigType type;
public void setBootstrap(Bootstrap bootstrap) {
this.bootstrap = bootstrap;
}
private String maxRetry;
public static class Bootstrap {
private String configLongPollTimeout;
private boolean enable = false;
private String configRetryTime;
private boolean logEnable = false;
private boolean autoRefresh = false;
public boolean isEnable() {
return enable;
}
private boolean enableRemoteSyncConfig = false;
public void setEnable(boolean enable) {
this.enable = enable;
}
public String getServerAddr() {
return serverAddr;
}
public boolean isLogEnable() {
return logEnable;
}
public void setServerAddr(String serverAddr) {
this.serverAddr = serverAddr;
}
public void setLogEnable(boolean logEnable) {
this.logEnable = logEnable;
}
}
public String getEndpoint() {
return endpoint;
}
public static class Config {
public void setEndpoint(String endpoint) {
this.endpoint = endpoint;
}
private String serverAddr = "127.0.0.1:8848";
public String getNamespace() {
return namespace;
}
private String endpoint;
public void setNamespace(String namespace) {
this.namespace = namespace;
}
private String namespace;
public String getAccessKey() {
return accessKey;
}
private String accessKey;
public void setAccessKey(String accessKey) {
this.accessKey = accessKey;
}
private String secretKey;
public String getSecretKey() {
return secretKey;
}
private String ramRoleName;
public void setSecretKey(String secretKey) {
this.secretKey = secretKey;
}
private String dataId;
public String getDataId() {
return dataId;
}
private String dataIds;
public void setDataId(String dataId) {
this.dataId = dataId;
}
private String group = Constants.DEFAULT_GROUP;
public String getGroup() {
return group;
}
private ConfigType type;
public void setGroup(String group) {
this.group = group;
}
private String maxRetry;
public ConfigType getType() {
return type;
}
private String configLongPollTimeout;
public void setType(ConfigType type) {
this.type = type;
}
private String configRetryTime;
public String getMaxRetry() {
return maxRetry;
}
private boolean autoRefresh = false;
public void setMaxRetry(String maxRetry) {
this.maxRetry = maxRetry;
}
private boolean enableRemoteSyncConfig = false;
public String getConfigLongPollTimeout() {
return configLongPollTimeout;
}
public String getServerAddr() {
return serverAddr;
}
public void setConfigLongPollTimeout(String configLongPollTimeout) {
this.configLongPollTimeout = configLongPollTimeout;
}
public void setServerAddr(String serverAddr) {
this.serverAddr = serverAddr;
}
public String getConfigRetryTime() {
return configRetryTime;
}
public String getEndpoint() {
return endpoint;
}
public void setConfigRetryTime(String configRetryTime) {
this.configRetryTime = configRetryTime;
}
public void setEndpoint(String endpoint) {
this.endpoint = endpoint;
}
public boolean isAutoRefresh() {
return autoRefresh;
}
public String getNamespace() {
return namespace;
}
public void setAutoRefresh(boolean autoRefresh) {
this.autoRefresh = autoRefresh;
}
public void setNamespace(String namespace) {
this.namespace = namespace;
}
public boolean isEnableRemoteSyncConfig() {
return enableRemoteSyncConfig;
}
public String getAccessKey() {
return accessKey;
}
public void setEnableRemoteSyncConfig(boolean enableRemoteSyncConfig) {
this.enableRemoteSyncConfig = enableRemoteSyncConfig;
}
}
}
public void setAccessKey(String accessKey) {
this.accessKey = accessKey;
}
public String getSecretKey() {
return secretKey;
}
public void setSecretKey(String secretKey) {
this.secretKey = secretKey;
}
public String getRamRoleName() {
return ramRoleName;
}
public void setRamRoleName(String ramRoleName) {
this.ramRoleName = ramRoleName;
}
public String getDataId() {
return dataId;
}
public void setDataId(String dataId) {
this.dataId = dataId;
}
public String getDataIds() {
return dataIds;
}
public void setDataIds(String dataIds) {
this.dataIds = dataIds;
}
public String getGroup() {
return group;
}
public void setGroup(String group) {
this.group = group;
}
public ConfigType getType() {
return type;
}
public void setType(ConfigType type) {
this.type = type;
}
public String getMaxRetry() {
return maxRetry;
}
public void setMaxRetry(String maxRetry) {
this.maxRetry = maxRetry;
}
public String getConfigLongPollTimeout() {
return configLongPollTimeout;
}
public void setConfigLongPollTimeout(String configLongPollTimeout) {
this.configLongPollTimeout = configLongPollTimeout;
}
public String getConfigRetryTime() {
return configRetryTime;
}
public void setConfigRetryTime(String configRetryTime) {
this.configRetryTime = configRetryTime;
}
public boolean isAutoRefresh() {
return autoRefresh;
}
public void setAutoRefresh(boolean autoRefresh) {
this.autoRefresh = autoRefresh;
}
public boolean isEnableRemoteSyncConfig() {
return enableRemoteSyncConfig;
}
public void setEnableRemoteSyncConfig(boolean enableRemoteSyncConfig) {
this.enableRemoteSyncConfig = enableRemoteSyncConfig;
}
}
}

View File

@ -0,0 +1,87 @@
/*
* 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.boot.nacos.config.util;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;
/**
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
* @since 0.1.3
*/
public class AttributeExtractTask implements Callable<Map<String, Object>> {
private final String prefix;
private final ConfigurableEnvironment environment;
public AttributeExtractTask(String prefix, ConfigurableEnvironment environment) {
this.prefix = prefix;
this.environment = environment;
}
@Override
public Map<String, Object> call() throws Exception {
List<Map<String, Object>> defer = new LinkedList<>();
MutablePropertySources mutablePropertySources = environment.getPropertySources();
for (PropertySource propertySource : mutablePropertySources) {
calculate(propertySource.getSource(), defer);
}
Map<String, Object> result = new HashMap<>(32);
Collections.reverse(defer);
for (Map<String, Object> item : defer) {
result.putAll(item);
}
return result;
}
private void calculate(Object source, List<Map<String, Object>> defer) {
if (source instanceof PropertySource) {
calculate(((PropertySource) source).getSource(), defer);
}
if (source instanceof Map) {
Map<String, Object> map = new HashMap<>(8);
for (Object entry : ((Map) source).entrySet()) {
Map.Entry<Object, Object> element = (Map.Entry<Object, Object>) entry;
String key = String.valueOf(element.getKey());
if (key.startsWith(prefix)) {
map.put(key, element.getValue());
}
}
if (!map.isEmpty()) {
defer.add(map);
}
}
if (source instanceof List || source instanceof Set) {
Collection sources = (Collection) source;
for (Object obj : sources) {
calculate(obj, defer);
}
}
}
}

View File

@ -0,0 +1,36 @@
/*
* 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.boot.nacos.config.util;
import java.util.Properties;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.boot.bind.RelaxedDataBinder;
/**
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
* @since 0.1.4
*/
public final class BinderUtils {
public static <T> T bind(T obj, String prefix, Properties properties) {
RelaxedDataBinder binder = new RelaxedDataBinder(obj, prefix);
binder.bind(new MutablePropertyValues(properties));
return obj;
}
}

View File

@ -0,0 +1,33 @@
/*
* 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.boot.nacos.config.util;
/**
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
* @since 0.1.4
*/
public interface Function<F, T> {
/**
* apply F to T
*
* @param input input
* @return T
*/
T apply(F input);
}

View File

@ -16,89 +16,55 @@
*/
package com.alibaba.boot.nacos.config.util;
import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
import com.alibaba.boot.nacos.config.NacosConfigConstants;
import com.alibaba.boot.nacos.config.properties.NacosConfigProperties;
import com.alibaba.boot.nacos.config.util.editor.NacosCharSequenceEditor;
import com.alibaba.boot.nacos.config.util.editor.NacosCustomBooleanEditor;
import com.alibaba.boot.nacos.config.util.editor.NacosEnumEditor;
import com.alibaba.nacos.api.config.ConfigType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
import org.springframework.beans.propertyeditors.CustomCollectionEditor;
import org.springframework.boot.env.OriginTrackedMapPropertySource;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.springframework.core.env.ConfigurableEnvironment;
/**
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
* @since
* @since 0.1.3
*/
public class NacosConfigPropertiesUtils {
private static final Logger logger = LoggerFactory.getLogger(NacosConfigPropertiesUtils.class);
private static final String PROPERTIES_PREFIX = "nacos";
public static NacosConfigProperties buildNacosConfigProperties(ConfigurableEnvironment environment) {
BeanWrapper wrapper = new BeanWrapperImpl(new NacosConfigProperties());
wrapper.setAutoGrowNestedPaths(true);
wrapper.setExtractOldValueForEditor(true);
wrapper.registerCustomEditor(String.class, new NacosCharSequenceEditor());
wrapper.registerCustomEditor(boolean.class, new NacosCustomBooleanEditor(true));
wrapper.registerCustomEditor(ConfigType.class, new NacosEnumEditor(ConfigType.class));
wrapper.registerCustomEditor(Collection.class, new CustomCollectionEditor(ArrayList.class));
PropertySource target = findApplicationConfig(environment);
wrapper.setPropertyValues(dataSource((Map<String, String>) target.getSource()));
NacosConfigProperties nacosConfigProperties = (NacosConfigProperties) wrapper.getWrappedInstance();
logger.debug("nacosConfigProperties : {}", nacosConfigProperties);
return nacosConfigProperties;
}
private static final Logger logger = LoggerFactory
.getLogger(NacosConfigPropertiesUtils.class);
private static PropertySource<Map<String, String>> findApplicationConfig(ConfigurableEnvironment environment) {
PropertySource<Map<String, String>> target = null;
MutablePropertySources mutablePropertySources = environment.getPropertySources();
for (PropertySource tmp : mutablePropertySources) {
// Spring puts the information of the application.properties file into class{OriginTrackedMapPropertySource}.
if (tmp instanceof OriginTrackedMapPropertySource) {
target = tmp;
}
}
return target;
}
private static Set<String> OBJ_FIELD_NAME = new HashSet<>();
private static Map<String, String> dataSource(Map<String, String> source) {
source.remove(NacosConfigConstants.NACOS_BOOTSTRAP);
String prefix = NacosConfigConstants.PREFIX + ".";
HashMap<String, String> targetConfigInfo = new HashMap<>(source.size());
for (Map.Entry<String, String> entry : source.entrySet()) {
if (entry.getKey().startsWith(prefix)) {
String key = entry.getKey().replace(prefix, "");
if (key.contains("-")) {
String[] subs = key.split("-");
key = buildJavaField(subs);
}
targetConfigInfo.put(key, entry.getValue());
}
}
return targetConfigInfo;
}
static {
Field[] fields = NacosConfigProperties.class.getDeclaredFields();
for (Field field : fields) {
OBJ_FIELD_NAME.add(field.getName());
}
}
private static String buildJavaField(String[] subs) {
StringBuilder sb = new StringBuilder();
sb.append(subs[0]);
for (int i = 1; i < subs.length; i ++) {
char[] chars = subs[i].toCharArray();
chars[0] = Character.toUpperCase(chars[0]);
sb.append(chars);
}
return sb.toString();
}
public static NacosConfigProperties buildNacosConfigProperties(
ConfigurableEnvironment environment) {
NacosConfigProperties bean = new NacosConfigProperties();
AttributeExtractTask task = new AttributeExtractTask(PROPERTIES_PREFIX,
environment);
try {
Properties properties = new Properties();
properties.putAll(task.call());
BinderUtils.bind(bean, NacosConfigConstants.PREFIX, properties);
}
catch (Exception e) {
throw new RuntimeException(e);
}
logger.info("nacosConfigProperties : {}", bean);
return bean;
}
}

View File

@ -0,0 +1,222 @@
/*
* 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.boot.nacos.config.util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
import com.alibaba.boot.nacos.config.properties.NacosConfigProperties;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.config.ConfigType;
import com.alibaba.nacos.spring.core.env.NacosPropertySource;
import com.alibaba.nacos.spring.core.env.NacosPropertySourcePostProcessor;
import com.alibaba.nacos.spring.util.NacosUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MutablePropertySources;
import static com.alibaba.nacos.spring.util.NacosUtils.buildDefaultPropertySourceName;
/**
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
* @since 0.1.3
*/
public class NacosConfigUtils {
private final Logger logger = LoggerFactory.getLogger(NacosConfigUtils.class);
private final NacosConfigProperties nacosConfigProperties;
private final ConfigurableEnvironment environment;
private Function<Properties, ConfigService> builder;
private List<DeferNacosPropertySource> nacosPropertySources = new LinkedList<>();
public NacosConfigUtils(NacosConfigProperties nacosConfigProperties,
ConfigurableEnvironment environment,
Function<Properties, ConfigService> builder) {
this.nacosConfigProperties = nacosConfigProperties;
this.environment = environment;
this.builder = builder;
}
public void loadConfig() {
Properties globalProperties = buildGlobalNacosProperties();
MutablePropertySources mutablePropertySources = environment.getPropertySources();
List<NacosPropertySource> sources = reqGlobalNacosConfig(globalProperties,
nacosConfigProperties.getType());
for (NacosConfigProperties.Config config : nacosConfigProperties.getExtConfig()) {
List<NacosPropertySource> elements = reqSubNacosConfig(config,
globalProperties, config.getType());
sources.addAll(sources.size(), elements);
}
for (NacosPropertySource propertySource : sources) {
mutablePropertySources.addLast(propertySource);
}
}
private Properties buildGlobalNacosProperties() {
return NacosPropertiesBuilder.buildNacosProperties(
nacosConfigProperties.getServerAddr(),
nacosConfigProperties.getNamespace(), nacosConfigProperties.getEndpoint(),
nacosConfigProperties.getSecretKey(),
nacosConfigProperties.getAccessKey(),
nacosConfigProperties.getRamRoleName(),
nacosConfigProperties.getConfigLongPollTimeout(),
nacosConfigProperties.getConfigRetryTime(),
nacosConfigProperties.getMaxRetry(),
nacosConfigProperties.isEnableRemoteSyncConfig());
}
private Properties buildSubNacosProperties(Properties globalProperties,
NacosConfigProperties.Config config) {
return getProperties(globalProperties, config);
}
private static Properties getProperties(Properties globalProperties,
NacosConfigProperties.Config config) {
if (StringUtils.isEmpty(config.getServerAddr())) {
return globalProperties;
}
Properties sub = NacosPropertiesBuilder.buildNacosProperties(
config.getServerAddr(), config.getNamespace(), config.getEndpoint(),
config.getSecretKey(), config.getAccessKey(), config.getRamRoleName(),
config.getConfigLongPollTimeout(), config.getConfigRetryTime(),
config.getMaxRetry(), config.isEnableRemoteSyncConfig());
NacosPropertiesBuilder.merge(sub, globalProperties);
return sub;
}
private List<NacosPropertySource> reqGlobalNacosConfig(Properties globalProperties,
ConfigType type) {
List<String> dataIds = new ArrayList<>();
// Loads all data-id information into the list in the list
if (StringUtils.isEmpty(nacosConfigProperties.getDataId())) {
final String ids = environment
.resolvePlaceholders(nacosConfigProperties.getDataIds());
dataIds.addAll(Arrays.asList(ids.split(",")));
}
else {
dataIds.add(nacosConfigProperties.getDataId());
}
final String groupName = environment
.resolvePlaceholders(nacosConfigProperties.getGroup());
final boolean isAutoRefresh = nacosConfigProperties.isAutoRefresh();
return new ArrayList<>(Arrays.asList(reqNacosConfig(globalProperties,
dataIds.toArray(new String[0]), groupName, type, isAutoRefresh)));
}
private List<NacosPropertySource> reqSubNacosConfig(
NacosConfigProperties.Config config, Properties globalProperties,
ConfigType type) {
Properties subConfigProperties = buildSubNacosProperties(globalProperties,
config);
ArrayList<String> dataIds = new ArrayList<>();
if (StringUtils.isEmpty(config.getDataId())) {
final String ids = environment.resolvePlaceholders(config.getDataId());
dataIds.addAll(Arrays.asList(ids.split(",")));
}
else {
dataIds.add(config.getDataId());
}
final String groupName = environment.resolvePlaceholders(config.getGroup());
final boolean isAutoRefresh = config.isAutoRefresh();
return new ArrayList<>(Arrays.asList(reqNacosConfig(subConfigProperties,
dataIds.toArray(new String[0]), groupName, type, isAutoRefresh)));
}
private NacosPropertySource[] reqNacosConfig(Properties configProperties,
String[] dataIds, String groupId, ConfigType type, boolean isAutoRefresh) {
final NacosPropertySource[] propertySources = new NacosPropertySource[dataIds.length];
for (int i = 0; i < dataIds.length; i++) {
if (StringUtils.isEmpty(dataIds[i])) {
continue;
}
final String dataId = environment.resolvePlaceholders(dataIds[i].trim());
final String config = NacosUtils.getContent(builder.apply(configProperties),
dataId, groupId);
final NacosPropertySource nacosPropertySource = new NacosPropertySource(
dataId, groupId,
buildDefaultPropertySourceName(dataId, groupId, configProperties),
config, type.getType());
nacosPropertySource.setDataId(dataId);
nacosPropertySource.setType(type.getType());
nacosPropertySource.setGroupId(groupId);
nacosPropertySource.setAutoRefreshed(isAutoRefresh);
logger.info(
"load config from nacos, data-id is : [{}], group is : [{}], config-text is : [{}]",
dataId, groupId, config);
propertySources[i] = nacosPropertySource;
DeferNacosPropertySource defer = new DeferNacosPropertySource(
nacosPropertySource, configProperties, environment);
nacosPropertySources.add(defer);
}
return propertySources;
}
public void addListenerIfAutoRefreshed() {
addListenerIfAutoRefreshed(nacosPropertySources);
}
public void addListenerIfAutoRefreshed(
final List<DeferNacosPropertySource> deferNacosPropertySources) {
for (DeferNacosPropertySource deferNacosPropertySource : deferNacosPropertySources) {
NacosPropertySourcePostProcessor.addListenerIfAutoRefreshed(
deferNacosPropertySource.getNacosPropertySource(),
deferNacosPropertySource.getProperties(),
deferNacosPropertySource.getEnvironment());
}
}
public List<DeferNacosPropertySource> getNacosPropertySources() {
return nacosPropertySources;
}
// Delay Nacos configuration data source object, used for log level of loading time,
// the cache configuration, wait for after the completion of the Spring Context
// created in the release
public static class DeferNacosPropertySource {
private final NacosPropertySource nacosPropertySource;
private final ConfigurableEnvironment environment;
private final Properties properties;
DeferNacosPropertySource(NacosPropertySource nacosPropertySource,
Properties properties, ConfigurableEnvironment environment) {
this.nacosPropertySource = nacosPropertySource;
this.properties = properties;
this.environment = environment;
}
NacosPropertySource getNacosPropertySource() {
return nacosPropertySource;
}
ConfigurableEnvironment getEnvironment() {
return environment;
}
public Properties getProperties() {
return properties;
}
}
}

View File

@ -16,65 +16,73 @@
*/
package com.alibaba.boot.nacos.config.util;
import com.alibaba.nacos.api.PropertyKeyConst;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;
import java.util.Map;
import java.util.Properties;
import com.alibaba.nacos.api.PropertyKeyConst;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;
/**
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
* @since
* @since 0.1.3
*/
public class NacosPropertiesBuilder {
public static Properties buildNacosProperties(String serverAddr, String namespaceId, String endpoint, String secreyKey,
String accessKey, String configLongPollTimeout, String configRetryTimeout, String maxRetry, boolean enableRemoteSyncConfig) {
public static Properties buildNacosProperties(String serverAddr, String namespaceId,
String endpoint, String secretKey, String accessKey, String ramRoleName,
String configLongPollTimeout, String configRetryTimeout, String maxRetry,
boolean enableRemoteSyncConfig) {
Properties properties = new Properties();
if (StringUtils.isNotEmpty(serverAddr)) {
properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr);
}
if (StringUtils.isNotEmpty(namespaceId)) {
properties.put(PropertyKeyConst.NAMESPACE, namespaceId);
}
if (StringUtils.isNotEmpty(endpoint)) {
properties.put(PropertyKeyConst.ENDPOINT, endpoint);
}
if (StringUtils.isNotEmpty(secreyKey)) {
properties.put(PropertyKeyConst.SECRET_KEY, secreyKey);
}
if (StringUtils.isNotEmpty(accessKey)) {
properties.put(PropertyKeyConst.ACCESS_KEY, accessKey);
}
if (StringUtils.isNotEmpty(configLongPollTimeout)) {
properties.put(PropertyKeyConst.CONFIG_LONG_POLL_TIMEOUT, configLongPollTimeout);
}
if (StringUtils.isNotEmpty(configRetryTimeout)) {
properties.put(PropertyKeyConst.CONFIG_RETRY_TIME, configRetryTimeout);
}
if (StringUtils.isNotEmpty(maxRetry)) {
properties.put(PropertyKeyConst.MAX_RETRY, maxRetry);
}
properties.put(PropertyKeyConst.ENABLE_REMOTE_SYNC_CONFIG, String.valueOf(enableRemoteSyncConfig));
return properties;
}
Properties properties = new Properties();
if (StringUtils.isNotEmpty(serverAddr)) {
properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr);
}
if (StringUtils.isNotEmpty(namespaceId)) {
properties.put(PropertyKeyConst.NAMESPACE, namespaceId);
}
if (StringUtils.isNotEmpty(endpoint)) {
properties.put(PropertyKeyConst.ENDPOINT, endpoint);
}
if (StringUtils.isNotEmpty(secretKey)) {
properties.put(PropertyKeyConst.SECRET_KEY, secretKey);
}
if (StringUtils.isNotEmpty(accessKey)) {
properties.put(PropertyKeyConst.ACCESS_KEY, accessKey);
}
if (StringUtils.isNoneEmpty(ramRoleName)) {
properties.put(PropertyKeyConst.RAM_ROLE_NAME, ramRoleName);
}
if (StringUtils.isNotEmpty(configLongPollTimeout)) {
properties.put(PropertyKeyConst.CONFIG_LONG_POLL_TIMEOUT,
configLongPollTimeout);
}
if (StringUtils.isNotEmpty(configRetryTimeout)) {
properties.put(PropertyKeyConst.CONFIG_RETRY_TIME, configRetryTimeout);
}
if (StringUtils.isNotEmpty(maxRetry)) {
properties.put(PropertyKeyConst.MAX_RETRY, maxRetry);
}
properties.put(PropertyKeyConst.ENABLE_REMOTE_SYNC_CONFIG,
String.valueOf(enableRemoteSyncConfig));
return properties;
}
public static void merge(Properties targetProperties, Properties sourceProperties) {
public static void merge(Properties targetProperties, Properties sourceProperties) {
if (CollectionUtils.isEmpty(sourceProperties)) {
return;
}
if (CollectionUtils.isEmpty(sourceProperties)) {
return;
}
for (Map.Entry entry : sourceProperties.entrySet()) {
String propertyName = (String) entry.getKey();
if (!targetProperties.containsKey(propertyName)) {
String propertyValue = (String) entry.getValue();
targetProperties.setProperty(propertyName, propertyValue);
}
}
for (Map.Entry entry : sourceProperties.entrySet()) {
String propertyName = (String) entry.getKey();
if (!targetProperties.containsKey(propertyName)) {
String propertyValue = (String) entry.getValue();
targetProperties.setProperty(propertyName, propertyValue);
}
}
}
}
}
}

View File

@ -0,0 +1,72 @@
/*
* 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.boot.nacos.config.util.editor;
import java.beans.PropertyEditorSupport;
/**
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
* @since 0.1.3
*/
public class NacosBooleanEditor extends PropertyEditorSupport {
public NacosBooleanEditor() {
}
@Override
public String getJavaInitializationString() {
Object var1 = this.getValue();
return var1 != null ? var1.toString() : "null";
}
@Override
public String getAsText() {
Object var1 = this.getValue();
return var1 instanceof Boolean ? this.getValidName((Boolean) var1) : null;
}
@Override
public void setAsText(String var1) throws IllegalArgumentException {
if (var1 == null) {
this.setValue((Object) null);
}
else if (this.isValidName(true, var1)) {
this.setValue(Boolean.TRUE);
}
else {
if (!this.isValidName(false, var1)) {
throw new IllegalArgumentException(var1);
}
this.setValue(Boolean.FALSE);
}
}
@Override
public String[] getTags() {
return new String[] { this.getValidName(true), this.getValidName(false) };
}
private String getValidName(boolean var1) {
return var1 ? "True" : "False";
}
private boolean isValidName(boolean var1, String var2) {
return this.getValidName(var1).equalsIgnoreCase(var2);
}
}

View File

@ -1,108 +0,0 @@
/*
* 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.boot.nacos.config.util.editor;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
import java.beans.PropertyEditorSupport;
/**
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
* @since
*/
public class NacosCustomBooleanEditor extends PropertyEditorSupport {
public static final String VALUE_TRUE = "true";
public static final String VALUE_FALSE = "false";
public static final String VALUE_ON = "on";
public static final String VALUE_OFF = "off";
public static final String VALUE_YES = "yes";
public static final String VALUE_NO = "no";
public static final String VALUE_1 = "1";
public static final String VALUE_0 = "0";
@Nullable
private final String trueString;
@Nullable
private final String falseString;
private final boolean allowEmpty;
public NacosCustomBooleanEditor(boolean allowEmpty) {
this(null, null, allowEmpty);
}
public NacosCustomBooleanEditor(@Nullable String trueString, @Nullable String falseString, boolean allowEmpty) {
this.trueString = trueString;
this.falseString = falseString;
this.allowEmpty = allowEmpty;
}
@Override
public void setValue(Object value) {
super.setValue(convert(String.valueOf(value)));
}
public Object convert(String text) throws IllegalArgumentException {
String input = (text != null ? text.trim() : null);
if (this.allowEmpty && !StringUtils.hasLength(input)) {
// Treat empty String as null value.
return null;
}
else if (this.trueString != null && this.trueString.equalsIgnoreCase(input)) {
return Boolean.TRUE;
}
else if (this.falseString != null && this.falseString.equalsIgnoreCase(input)) {
return Boolean.FALSE;
}
else if (this.trueString == null &&
(VALUE_TRUE.equalsIgnoreCase(input) || VALUE_ON.equalsIgnoreCase(input) ||
VALUE_YES.equalsIgnoreCase(input) || VALUE_1.equals(input))) {
return Boolean.TRUE;
}
else if (this.falseString == null &&
(VALUE_FALSE.equalsIgnoreCase(input) || VALUE_OFF.equalsIgnoreCase(input) ||
VALUE_NO.equalsIgnoreCase(input) || VALUE_0.equals(input))) {
return Boolean.FALSE;
}
else {
throw new IllegalArgumentException("Invalid boolean value [" + text + "]");
}
}
@Override
public String getAsText() {
String t = String.valueOf(getValue());
if (Boolean.TRUE.equals(Boolean.valueOf(t))) {
return (this.trueString != null ? this.trueString : VALUE_TRUE);
}
else if (Boolean.FALSE.equals(Boolean.valueOf(t))) {
return (this.falseString != null ? this.falseString : VALUE_FALSE);
}
else {
return "";
}
}
}

View File

@ -16,11 +16,7 @@
*/
package com.alibaba.boot.nacos.config.util.editor;
import com.alibaba.nacos.api.config.ConfigType;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.Component;
import java.awt.*;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyEditor;
@ -29,127 +25,133 @@ import java.util.List;
/**
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
* @since
* @since 0.1.3
*/
public class NacosEnumEditor implements PropertyEditor {
private final List<PropertyChangeListener> listeners = new ArrayList();
private final Class type;
private final String[] tags;
private Object value;
private final List<PropertyChangeListener> listeners = new ArrayList();
private final Class type;
private final String[] tags;
private Object value;
public NacosEnumEditor(Class var1) {
Object[] var2 = var1.getEnumConstants();
if (var2 == null) {
throw new IllegalArgumentException("Unsupported " + var1);
} else {
this.type = var1;
this.tags = new String[var2.length];
public NacosEnumEditor(Class var1) {
Object[] var2 = var1.getEnumConstants();
if (var2 == null) {
throw new IllegalArgumentException("Unsupported " + var1);
}
else {
this.type = var1;
this.tags = new String[var2.length];
for(int var3 = 0; var3 < var2.length; ++var3) {
this.tags[var3] = ((Enum)var2[var3]).name();
}
}
}
for (int var3 = 0; var3 < var2.length; ++var3) {
this.tags[var3] = ((Enum) var2[var3]).name();
}
}
}
@Override
public Object getValue() {
return this.value;
}
@Override
public Object getValue() {
return this.value;
}
@Override
public void setValue(Object var1) {
if (var1 instanceof CharSequence) {
ConfigType bean = ConfigType.valueOf(String.valueOf(var1).toUpperCase());
Object var2;
PropertyChangeListener[] var3;
synchronized(this.listeners) {
label45: {
var2 = this.value;
this.value = bean;
if (bean == null) {
if (var2 != null) {
break label45;
}
} else if (!bean.equals(var2)) {
break label45;
}
@Override
public void setValue(Object var1) {
if (var1 != null && !this.type.isInstance(var1)) {
throw new IllegalArgumentException("Unsupported value: " + var1);
}
else {
Object var2;
PropertyChangeListener[] var3;
synchronized (this.listeners) {
label45: {
var2 = this.value;
this.value = var1;
if (var1 == null) {
if (var2 != null) {
break label45;
}
}
else if (!var1.equals(var2)) {
break label45;
}
return;
}
return;
}
int var5 = this.listeners.size();
if (var5 == 0) {
return;
}
int var5 = this.listeners.size();
if (var5 == 0) {
return;
}
var3 = (PropertyChangeListener[])this.listeners.toArray(new PropertyChangeListener[var5]);
}
var3 = (PropertyChangeListener[]) this.listeners
.toArray(new PropertyChangeListener[var5]);
}
PropertyChangeEvent var4 = new PropertyChangeEvent(this, (String)null, var2, bean);
PropertyChangeListener[] var10 = var3;
int var6 = var3.length;
PropertyChangeEvent var4 = new PropertyChangeEvent(this, (String) null, var2,
var1);
PropertyChangeListener[] var10 = var3;
int var6 = var3.length;
for(int var7 = 0; var7 < var6; ++var7) {
PropertyChangeListener var8 = var10[var7];
var8.propertyChange(var4);
}
for (int var7 = 0; var7 < var6; ++var7) {
PropertyChangeListener var8 = var10[var7];
var8.propertyChange(var4);
}
}
}
}
}
@Override
public String getAsText() {
return this.value != null ? ((Enum)this.value).name() : null;
}
@Override
public String getAsText() {
return this.value != null ? ((Enum) this.value).name() : null;
}
@Override
public void setAsText(String var1) {
this.setValue(var1 != null ? Enum.valueOf(this.type, var1) : null);
}
@Override
public void setAsText(String var1) {
this.setValue(var1 != null ? Enum.valueOf(this.type, var1.toUpperCase()) : null);
}
@Override
public String[] getTags() {
return (String[])this.tags.clone();
}
@Override
public String[] getTags() {
return (String[]) this.tags.clone();
}
@Override
public String getJavaInitializationString() {
String var1 = this.getAsText();
return var1 != null ? this.type.getName() + '.' + var1 : "null";
}
@Override
public String getJavaInitializationString() {
String var1 = this.getAsText();
return var1 != null ? this.type.getName() + '.' + var1 : "null";
}
@Override
public boolean isPaintable() {
return false;
}
@Override
public boolean isPaintable() {
return false;
}
@Override
public void paintValue(Graphics var1, Rectangle var2) {
}
@Override
public void paintValue(Graphics var1, Rectangle var2) {
}
@Override
public boolean supportsCustomEditor() {
return false;
}
@Override
public boolean supportsCustomEditor() {
return false;
}
@Override
public Component getCustomEditor() {
return null;
}
@Override
public Component getCustomEditor() {
return null;
}
@Override
public void addPropertyChangeListener(PropertyChangeListener var1) {
synchronized(this.listeners) {
this.listeners.add(var1);
}
}
@Override
public void addPropertyChangeListener(PropertyChangeListener var1) {
synchronized (this.listeners) {
this.listeners.add(var1);
}
}
@Override
public void removePropertyChangeListener(PropertyChangeListener var1) {
synchronized(this.listeners) {
this.listeners.remove(var1);
}
}
@Override
public void removePropertyChangeListener(PropertyChangeListener var1) {
synchronized (this.listeners) {
this.listeners.remove(var1);
}
}
}

View File

@ -0,0 +1,96 @@
/*
* 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.boot.nacos.config.util.editor;
import java.beans.PropertyEditorSupport;
/**
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
* @since 0.1.3
*/
public class NacosStringEditor extends PropertyEditorSupport {
public NacosStringEditor() {
}
@Override
public String getJavaInitializationString() {
Object var1 = this.getValue();
if (var1 == null) {
return "null";
}
else {
String var2 = var1.toString();
int var3 = var2.length();
StringBuilder var4 = new StringBuilder(var3 + 2);
var4.append('"');
for (int var5 = 0; var5 < var3; ++var5) {
char var6 = var2.charAt(var5);
String var7;
int var8;
switch (var6) {
case '\b':
var4.append("\\b");
continue;
case '\t':
var4.append("\\t");
continue;
case '\n':
var4.append("\\n");
continue;
case '\f':
var4.append("\\f");
continue;
case '\r':
var4.append("\\r");
continue;
case '"':
var4.append("\\\"");
continue;
case '\\':
var4.append("\\\\");
continue;
default:
if (var6 >= ' ' && var6 <= '~') {
var4.append(var6);
continue;
}
var4.append("\\u");
var7 = Integer.toHexString(var6);
var8 = var7.length();
}
while (var8 < 4) {
var4.append('0');
++var8;
}
var4.append(var7);
}
var4.append('"');
return var4.toString();
}
}
@Override
public void setAsText(String var1) {
this.setValue(var1);
}
}

View File

@ -50,11 +50,22 @@
"description": "the secretkey of Alibaba Cloud Account",
"type": "java.lang.String"
},
{
"sourceType": "com.alibaba.boot.nacos.config.properties.NacosConfigProperties",
"name": "nacos.config.ram-role-name",
"description": "the ramRoleName of Alibaba Cloud Account",
"type": "java.lang.String"
},
{
"sourceType": "com.alibaba.boot.nacos.config.properties.NacosConfigProperties",
"name": "nacos.config.data-id",
"type": "java.lang.String"
},
{
"sourceType": "com.alibaba.boot.nacos.config.properties.NacosConfigProperties",
"name": "nacos.config.data-ids",
"type": "java.lang.String"
},
{
"sourceType": "com.alibaba.boot.nacos.config.properties.NacosConfigProperties",
"name": "nacos.config.group",
@ -100,6 +111,12 @@
"description": "the secretkey of Alibaba Cloud Account",
"type": "java.lang.String"
},
{
"sourceType": "com.alibaba.boot.nacos.config.properties.NacosConfigProperties",
"name": "nacos.config.bootstrap.log.enable",
"description": "the secretkey of Alibaba Cloud Account",
"type": "java.lang.String"
},
{
"sourceType": "com.alibaba.boot.nacos.config.properties.NacosConfigProperties",
"name": "nacos.config.ext-config",

View File

@ -1,4 +1,4 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.alibaba.boot.nacos.config.autoconfigure.NacosConfigAutoConfiguration
org.springframework.context.ApplicationContextInitializer=\
com.alibaba.boot.nacos.config.autoconfigure.NacosConfigApplicationContextInitializer
org.springframework.boot.env.EnvironmentPostProcessor=\
com.alibaba.boot.nacos.config.autoconfigure.NacosConfigEnvironmentProcessor

View File

@ -16,6 +16,8 @@
*/
package com.alibaba.boot.nacos.autoconfigure;
import java.util.Properties;
import com.alibaba.boot.nacos.config.autoconfigure.NacosConfigAutoConfiguration;
import com.alibaba.boot.nacos.config.properties.NacosConfigProperties;
import com.alibaba.nacos.api.PropertyKeyConst;
@ -25,6 +27,7 @@ import com.alibaba.nacos.spring.util.NacosBeanUtils;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@ -32,8 +35,6 @@ import org.springframework.context.ApplicationContext;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.Properties;
/**
* {@link NacosConfigAutoConfiguration} Test
*
@ -41,46 +42,46 @@ import java.util.Properties;
* @see NacosConfigAutoConfiguration
*/
@RunWith(SpringJUnit4ClassRunner.class)
@TestPropertySource(
properties = {
"nacos.config.server-addr=localhost"
}
)
@SpringBootTest(
classes = {NacosConfigAutoConfiguration.class}
)
@TestPropertySource(properties = { "nacos.config.server-addr=localhost" })
@SpringBootTest(classes = { NacosConfigAutoConfiguration.class })
public class NacosConfigAutoConfigurationTest {
@Autowired
private NacosConfigProperties nacosConfigProperties;
@Autowired
private NacosConfigProperties nacosConfigProperties;
@Autowired
private ApplicationContext applicationContext;
@Autowired
private ApplicationContext applicationContext;
@NacosInjected
private ConfigService configService;
@NacosInjected
private ConfigService configService;
@Test
public void testNacosConfig() {
Assert.assertNotNull(configService);
Assert.assertNotNull(applicationContext.getBean(NacosBeanUtils.CONFIG_GLOBAL_NACOS_PROPERTIES_BEAN_NAME));
Assert.assertEquals("localhost", nacosConfigProperties.getServerAddr());
}
@Test
public void testNacosConfig() {
Assert.assertNotNull(configService);
Assert.assertNotNull(applicationContext
.getBean(NacosBeanUtils.CONFIG_GLOBAL_NACOS_PROPERTIES_BEAN_NAME));
Assert.assertEquals("localhost", nacosConfigProperties.getServerAddr());
}
@Test(expected = NoSuchBeanDefinitionException.class)
public void testNacosConfigGlobalBean() {
Assert.assertNull(applicationContext.getBean(NacosBeanUtils.GLOBAL_NACOS_PROPERTIES_BEAN_NAME));
}
@Test(expected = NoSuchBeanDefinitionException.class)
public void testNacosConfigGlobalBean() {
Assert.assertNull(applicationContext
.getBean(NacosBeanUtils.GLOBAL_NACOS_PROPERTIES_BEAN_NAME));
}
@Test(expected = NoSuchBeanDefinitionException.class)
public void testNacosDiscoveryGlobalBean() {
Assert.assertNull(applicationContext.getBean(NacosBeanUtils.DISCOVERY_GLOBAL_NACOS_PROPERTIES_BEAN_NAME));
}
@Test(expected = NoSuchBeanDefinitionException.class)
public void testNacosDiscoveryGlobalBean() {
Assert.assertNull(applicationContext
.getBean(NacosBeanUtils.DISCOVERY_GLOBAL_NACOS_PROPERTIES_BEAN_NAME));
}
@Test
public void testNacosGlobalProperties() {
Properties properties = applicationContext.getBean(NacosBeanUtils.CONFIG_GLOBAL_NACOS_PROPERTIES_BEAN_NAME, Properties.class);
Assert.assertEquals("localhost", properties.getProperty(PropertyKeyConst.SERVER_ADDR));
}
@Test
public void testNacosGlobalProperties() {
Properties properties = applicationContext.getBean(
NacosBeanUtils.CONFIG_GLOBAL_NACOS_PROPERTIES_BEAN_NAME,
Properties.class);
Assert.assertEquals("localhost",
properties.getProperty(PropertyKeyConst.SERVER_ADDR));
}
}

View File

@ -18,7 +18,7 @@
<parent>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-spring-boot-parent</artifactId>
<version>0.9.0</version>
<version>0.1.4</version>
<relativePath>../nacos-spring-boot-parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -18,7 +18,7 @@
<parent>
<artifactId>nacos-spring-boot-parent</artifactId>
<groupId>com.alibaba.boot</groupId>
<version>0.9.0</version>
<version>0.1.4</version>
<relativePath>../nacos-spring-boot-parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -16,14 +16,16 @@
*/
package com.alibaba.boot.nacos.discovery.actuate.autoconfigure;
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import com.alibaba.boot.nacos.discovery.NacosDiscoveryConstants;
import com.alibaba.boot.nacos.discovery.actuate.endpoint.NacosDiscoveryEndpoint;
import org.springframework.boot.actuate.condition.ConditionalOnEnabledEndpoint;
import org.springframework.boot.actuate.endpoint.Endpoint;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.alibaba.boot.nacos.discovery.actuate.endpoint.NacosDiscoveryEndpoint;
/**
* Nacos Discovery {@link Endpoint} Auto-{@link Configuration}
*
@ -31,11 +33,12 @@ import com.alibaba.boot.nacos.discovery.actuate.endpoint.NacosDiscoveryEndpoint;
* @see Endpoint
*/
@Configuration
@ConditionalOnClass(Endpoint.class)
public class NacosDiscoveryEndpointsAutoConfiguration {
@Bean
@ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint
@ConditionalOnEnabledEndpoint(NacosDiscoveryConstants.ENDPOINT_PREFIX)
public NacosDiscoveryEndpoint nacosDiscoveryEndpoint() {
return new NacosDiscoveryEndpoint();
}

View File

@ -16,8 +16,12 @@
*/
package com.alibaba.boot.nacos.discovery.actuate.autoconfigure;
import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
import com.alibaba.boot.nacos.discovery.NacosDiscoveryConstants;
import com.alibaba.boot.nacos.discovery.actuate.health.NacosDiscoveryHealthIndicator;
import com.alibaba.boot.nacos.discovery.autoconfigure.NacosDiscoveryAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.ConditionalOnEnabledHealthIndicator;
import org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
@ -26,10 +30,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.alibaba.boot.nacos.discovery.NacosDiscoveryConstants;
import com.alibaba.boot.nacos.discovery.actuate.health.NacosDiscoveryHealthIndicator;
import com.alibaba.boot.nacos.discovery.autoconfigure.NacosDiscoveryAutoConfiguration;
/**
* Nacos {@link NacosDiscoveryHealthIndicator} Auto Configuration
*

View File

@ -16,50 +16,54 @@
*/
package com.alibaba.boot.nacos.discovery.actuate.endpoint;
import static com.alibaba.nacos.spring.util.NacosBeanUtils.DISCOVERY_GLOBAL_NACOS_PROPERTIES_BEAN_NAME;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
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.context.ApplicationContext;
import com.alibaba.boot.nacos.common.PropertiesUtils;
import com.alibaba.boot.nacos.discovery.NacosDiscoveryConstants;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.spring.factory.CacheableEventPublishingNacosServiceFactory;
import com.alibaba.nacos.spring.factory.NacosServiceFactory;
import com.alibaba.nacos.spring.util.NacosUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
import org.springframework.boot.actuate.endpoint.Endpoint;
import org.springframework.context.ApplicationContext;
import static com.alibaba.nacos.spring.util.NacosBeanUtils.DISCOVERY_GLOBAL_NACOS_PROPERTIES_BEAN_NAME;
/**
* Actuator {@link Endpoint} to expose Nacos Discovery Meta Data
*
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
* @see Endpoint
*/
@Endpoint(id = NacosDiscoveryConstants.ENDPOINT_PREFIX)
public class NacosDiscoveryEndpoint {
public class NacosDiscoveryEndpoint extends AbstractEndpoint<Map<String, Object>> {
@Autowired
private ApplicationContext applicationContext;
private static final Integer PAGE_SIZE = 100;
@ReadOperation
public NacosDiscoveryEndpoint() {
super(NacosDiscoveryConstants.ENDPOINT_PREFIX);
}
@Override
public Map<String, Object> invoke() {
Map<String, Object> result = new HashMap<>();
Map<String, Object> result = new HashMap<>(8);
result.put("nacosDiscoveryGlobalProperties",
PropertiesUtils.extractSafeProperties(applicationContext.getBean(
DISCOVERY_GLOBAL_NACOS_PROPERTIES_BEAN_NAME, Properties.class)));
NacosServiceFactory nacosServiceFactory = CacheableEventPublishingNacosServiceFactory.getSingleton();
NacosServiceFactory nacosServiceFactory = CacheableEventPublishingNacosServiceFactory
.getSingleton();
;
JSONArray array = new JSONArray();
for (NamingService namingService : nacosServiceFactory.getNamingServices()) {
@ -70,9 +74,9 @@ public class NacosDiscoveryEndpoint {
jsonObject.put("subscribeServices", namingService.getSubscribeServices());
array.add(jsonObject);
}
catch (NacosException e) {
jsonObject.put("serverStatus", namingService.getServerStatus() + ": "
+ e.getErrCode() + NacosUtils.SEPARATOR + e.getErrMsg());
catch (Exception e) {
jsonObject.put("serverStatus", namingService.getServerStatus()
+ NacosUtils.SEPARATOR + e.getMessage());
}
}

View File

@ -18,19 +18,19 @@ package com.alibaba.boot.nacos.discovery.actuate.health;
import java.util.Properties;
import com.alibaba.boot.nacos.common.PropertiesUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.spring.factory.CacheableEventPublishingNacosServiceFactory;
import com.alibaba.nacos.spring.factory.NacosServiceFactory;
import com.alibaba.nacos.spring.metadata.NacosServiceMetaData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.context.ApplicationContext;
import com.alibaba.boot.nacos.common.PropertiesUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.spring.factory.CacheableEventPublishingNacosServiceFactory;
import com.alibaba.nacos.spring.metadata.NacosServiceMetaData;
/**
* Nacos Discovery {@link HealthIndicator}
*
@ -47,7 +47,8 @@ public class NacosDiscoveryHealthIndicator extends AbstractHealthIndicator {
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
builder.up();
NacosServiceFactory nacosServiceFactory = CacheableEventPublishingNacosServiceFactory.getSingleton();
NacosServiceFactory nacosServiceFactory = CacheableEventPublishingNacosServiceFactory
.getSingleton();
for (NamingService namingService : nacosServiceFactory.getNamingServices()) {
if (namingService instanceof NacosServiceMetaData) {
NacosServiceMetaData nacosServiceMetaData = (NacosServiceMetaData) namingService;

View File

@ -19,18 +19,18 @@ package com.alibaba.boot.nacos.actuate.endpoint;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.boot.nacos.discovery.actuate.endpoint.NacosDiscoveryEndpoint;
import com.alibaba.boot.nacos.discovery.autoconfigure.NacosDiscoveryAutoConfiguration;
import com.alibaba.nacos.api.PropertyKeyConst;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import com.alibaba.boot.nacos.discovery.actuate.endpoint.NacosDiscoveryEndpoint;
import com.alibaba.boot.nacos.discovery.autoconfigure.NacosDiscoveryAutoConfiguration;
import com.alibaba.nacos.api.PropertyKeyConst;
/**
* {@link NacosDiscoveryEndpoint} Test
*

View File

@ -18,7 +18,7 @@
<parent>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-spring-boot-parent</artifactId>
<version>0.9.0</version>
<version>0.1.4</version>
<relativePath>../nacos-spring-boot-parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -25,9 +25,9 @@ import com.alibaba.nacos.spring.context.annotation.discovery.EnableNacosDiscover
*/
public interface NacosDiscoveryConstants {
String ENDPOINT_PREFIX = "nacos-discovery";
String ENDPOINT_PREFIX = "nacos_discovery";
String ENABLED = EnableNacosDiscovery.DISCOVERY_PREFIX + "enabled";
String ENABLED = EnableNacosDiscovery.DISCOVERY_PREFIX + "enabled";
String PREFIX = "nacos.discovery";
String PREFIX = "nacos.discovery";
}

View File

@ -0,0 +1,28 @@
/*
* 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.boot.nacos.discovery.autoconfigure;
/**
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
* @since 0.1.4
*/
public class AutoDeregisterException extends RuntimeException {
public AutoDeregisterException(Throwable cause) {
super(cause);
}
}

View File

@ -0,0 +1,28 @@
/*
* 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.boot.nacos.discovery.autoconfigure;
/**
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
* @since 0.1.3
*/
public class AutoRegisterException extends RuntimeException {
public AutoRegisterException(Throwable cause) {
super(cause);
}
}

View File

@ -16,17 +16,18 @@
*/
package com.alibaba.boot.nacos.discovery.autoconfigure;
import static com.alibaba.nacos.spring.util.NacosBeanUtils.DISCOVERY_GLOBAL_NACOS_PROPERTIES_BEAN_NAME;
import com.alibaba.boot.nacos.discovery.NacosDiscoveryConstants;
import com.alibaba.boot.nacos.discovery.properties.NacosDiscoveryProperties;
import com.alibaba.nacos.spring.context.annotation.discovery.EnableNacosDiscovery;
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.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.alibaba.boot.nacos.discovery.NacosDiscoveryConstants;
import com.alibaba.boot.nacos.discovery.properties.NacosDiscoveryProperties;
import com.alibaba.nacos.spring.context.annotation.discovery.EnableNacosDiscovery;
import static com.alibaba.nacos.spring.util.NacosBeanUtils.DISCOVERY_GLOBAL_NACOS_PROPERTIES_BEAN_NAME;
/**
* Nacos Discovery Auto {@link Configuration}
@ -37,7 +38,12 @@ import com.alibaba.nacos.spring.context.annotation.discovery.EnableNacosDiscover
@ConditionalOnMissingBean(name = DISCOVERY_GLOBAL_NACOS_PROPERTIES_BEAN_NAME)
@EnableNacosDiscovery
@EnableConfigurationProperties(value = NacosDiscoveryProperties.class)
@ConditionalOnClass(name = "org.springframework.boot.context.properties.bind.Binder")
@ConditionalOnClass(name = "org.springframework.boot.bind.RelaxedDataBinder")
public class NacosDiscoveryAutoConfiguration {
@Bean
public NacosDiscoveryAutoRegister discoveryAutoRegister() {
return new NacosDiscoveryAutoRegister();
}
}

View File

@ -0,0 +1,91 @@
/*
* 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.boot.nacos.discovery.autoconfigure;
import com.alibaba.boot.nacos.discovery.properties.NacosDiscoveryProperties;
import com.alibaba.boot.nacos.discovery.properties.Register;
import com.alibaba.nacos.api.annotation.NacosInjected;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.client.naming.utils.NetUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.embedded.EmbeddedServletContainer;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.stereotype.Component;
/**
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
* @since 0.1.4
*/
@Component
public class NacosDiscoveryAutoDeregister
implements ApplicationListener<ContextClosedEvent> {
private static final Logger logger = LoggerFactory
.getLogger(NacosDiscoveryAutoRegister.class);
@NacosInjected
private NamingService namingService;
private final NacosDiscoveryProperties discoveryProperties;
private final EmbeddedServletContainer webServer;
@Value("${spring.application.name:spring.application.name}")
private String applicationName;
public NacosDiscoveryAutoDeregister(NacosDiscoveryProperties discoveryProperties,
EmbeddedServletContainer webServer) {
this.discoveryProperties = discoveryProperties;
this.webServer = webServer;
}
@Override
public void onApplicationEvent(ContextClosedEvent event) {
if (!discoveryProperties.isAutoRegister()) {
return;
}
Register register = discoveryProperties.getRegister();
if (StringUtils.isEmpty(register.getIp())) {
register.setIp(NetUtils.localIP());
}
if (register.getPort() == 0) {
register.setPort(webServer.getPort());
}
String serviceName = StringUtils.isEmpty(register.getServiceName())
? applicationName
: register.getServiceName();
try {
namingService.deregisterInstance(serviceName, register.getGroupName(),
register);
logger.info("Finished auto deregister service : {}, ip : {}, port : {}",
register.getServiceName(), register.getIp(), register.getPort());
}
catch (NacosException e) {
throw new AutoDeregisterException(e);
}
}
}

View File

@ -0,0 +1,89 @@
/*
* 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.boot.nacos.discovery.autoconfigure;
import com.alibaba.boot.nacos.discovery.properties.NacosDiscoveryProperties;
import com.alibaba.boot.nacos.discovery.properties.Register;
import com.alibaba.nacos.api.annotation.NacosInjected;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.client.naming.utils.NetUtils;
import org.apache.commons.lang3.StringUtils;
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.embedded.EmbeddedServletContainerInitializedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
/**
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
* @since 0.1.3
*/
@Component
public class NacosDiscoveryAutoRegister
implements ApplicationListener<EmbeddedServletContainerInitializedEvent> {
private static final Logger logger = LoggerFactory
.getLogger(NacosDiscoveryAutoRegister.class);
@NacosInjected
private NamingService namingService;
@Autowired
private NacosDiscoveryProperties discoveryProperties;
@Value("${spring.application.name:spring.application.name}")
private String application;
@Override
public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) {
if (!discoveryProperties.isAutoRegister()) {
return;
}
Register register = discoveryProperties.getRegister();
if (StringUtils.isEmpty(register.getIp())) {
register.setIp(NetUtils.localIP());
}
if (register.getPort() == 0) {
register.setPort(event.getSource().getPort());
}
register.getMetadata().put("preserved.register.source", "SPRING_BOOT");
register.setInstanceId("");
String serviceName = StringUtils.isEmpty(register.getServiceName()) ? application
: register.getServiceName();
try {
namingService.registerInstance(serviceName, register.getGroupName(),
register);
logger.info("Finished auto register service : {}, ip : {}, port : {}",
register.getServiceName(), register.getIp(), register.getPort());
}
catch (NacosException e) {
throw new RuntimeException(e);
}
}
}

View File

@ -17,7 +17,9 @@
package com.alibaba.boot.nacos.discovery.properties;
import com.alibaba.boot.nacos.discovery.NacosDiscoveryConstants;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.util.Assert;
/**
@ -28,9 +30,9 @@ import org.springframework.util.Assert;
@ConfigurationProperties(NacosDiscoveryConstants.PREFIX)
public class NacosDiscoveryProperties {
private String serverAddr;
private String serverAddr = "127.0.0.1:8848";
private String contextPath;
private String contextPath;
private String clusterName;
@ -42,60 +44,81 @@ public class NacosDiscoveryProperties {
private String secretKey;
public String getServerAddr() {
return serverAddr;
}
private boolean autoRegister = false;
public void setServerAddr(String serverAddr) {
Assert.notNull(serverAddr, "nacos discovery server-addr must not be null");
this.serverAddr = serverAddr;
}
@NestedConfigurationProperty
private Register register = new Register();
public String getContextPath() {
return contextPath;
}
public String getServerAddr() {
return serverAddr;
}
public void setContextPath(String contextPath) {
this.contextPath = contextPath;
}
public void setServerAddr(String serverAddr) {
Assert.notNull(serverAddr, "nacos discovery server-addr must not be null");
this.serverAddr = serverAddr;
}
public String getClusterName() {
return clusterName;
}
public String getContextPath() {
return contextPath;
}
public void setClusterName(String clusterName) {
this.clusterName = clusterName;
}
public void setContextPath(String contextPath) {
this.contextPath = contextPath;
}
public String getEndpoint() {
return endpoint;
}
public String getClusterName() {
return clusterName;
}
public void setEndpoint(String endpoint) {
this.endpoint = endpoint;
}
public void setClusterName(String clusterName) {
this.clusterName = clusterName;
}
public String getNamespace() {
return namespace;
}
public String getEndpoint() {
return endpoint;
}
public void setNamespace(String namespace) {
this.namespace = namespace;
}
public void setEndpoint(String endpoint) {
this.endpoint = endpoint;
}
public String getAccessKey() {
return accessKey;
}
public String getNamespace() {
return namespace;
}
public void setAccessKey(String accessKey) {
this.accessKey = accessKey;
}
public void setNamespace(String namespace) {
this.namespace = namespace;
}
public String getSecretKey() {
return secretKey;
}
public String getAccessKey() {
return accessKey;
}
public void setSecretKey(String secretKey) {
this.secretKey = secretKey;
}
public void setAccessKey(String accessKey) {
this.accessKey = accessKey;
}
public String getSecretKey() {
return secretKey;
}
public void setSecretKey(String secretKey) {
this.secretKey = secretKey;
}
public boolean isAutoRegister() {
return autoRegister;
}
public void setAutoRegister(boolean autoRegister) {
this.autoRegister = autoRegister;
}
public Register getRegister() {
return register;
}
public void setRegister(Register register) {
this.register = register;
}
}

View File

@ -0,0 +1,37 @@
/*
* 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.boot.nacos.discovery.properties;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.naming.pojo.Instance;
/**
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
* @since 0.1.3
*/
public class Register extends Instance {
private String groupName = Constants.DEFAULT_GROUP;
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
}

View File

@ -0,0 +1,10 @@
{
"groups": [
{
"sourceType": "com.alibaba.boot.nacos.discovery.properties.NacosDiscoveryProperties",
"name": "nacos.discovery.register",
"sourceMethod": "getInstance()",
"type": "com.alibaba.nacos.api.naming.pojo.Instance"
}
]
}

View File

@ -1,54 +1,66 @@
{
hints: [ ],
groups: [ ],
properties: [
"hints": [ ],
"groups": [ ],
"properties": [
{
sourceType: "com.alibaba.boot.nacos.discovery.properties.NacosDiscoveryProperties",
name: "nacos.discovery.enabled",
description: "enable or disable nacos discovery feature",
type: "java.lang.Boolean"
"sourceType": "com.alibaba.boot.nacos.discovery.properties.NacosDiscoveryProperties",
"name": "nacos.discovery.enabled",
"description": "enable or disable nacos discovery feature",
"type": "java.lang.Boolean"
},
{
sourceType: "com.alibaba.boot.nacos.discovery.properties.NacosDiscoveryProperties",
name: "nacos.discovery.server-addr",
description: "the server address of nacos",
type: "java.lang.String"
"sourceType": "com.alibaba.boot.nacos.discovery.properties.NacosDiscoveryProperties",
"name": "nacos.discovery.server-addr",
"description": "the server address of nacos",
"type": "java.lang.String"
},
{
sourceType: "com.alibaba.boot.nacos.discovery.properties.NacosDiscoveryProperties",
name: "nacos.discovery.context-path",
description: "the context path of nacos server",
type: "java.lang.String"
"sourceType": "com.alibaba.boot.nacos.discovery.properties.NacosDiscoveryProperties",
"name": "nacos.discovery.context-path",
"description": "the context path of nacos server",
"type": "java.lang.String"
},
{
sourceType: "com.alibaba.boot.nacos.discovery.properties.NacosDiscoveryProperties",
name: "nacos.discovery.endpoint",
description: "the entry domain name of a service in each region",
type: "java.lang.String"
"sourceType": "com.alibaba.boot.nacos.discovery.properties.NacosDiscoveryProperties",
"name": "nacos.discovery.endpoint",
"description": "the entry domain name of a service in each region",
"type": "java.lang.String"
},
{
sourceType: "com.alibaba.boot.nacos.discovery.properties.NacosDiscoveryProperties",
name: "nacos.discovery.cluster-name",
description: "cluster info under service",
type: "java.lang.String"
"sourceType": "com.alibaba.boot.nacos.discovery.properties.NacosDiscoveryProperties",
"name": "nacos.discovery.cluster-name",
"description": "cluster info under service",
"type": "java.lang.String"
},
{
sourceType: "com.alibaba.boot.nacos.discovery.properties.NacosDiscoveryProperties",
name: "nacos.discovery.namespace",
description: "for configuration isolation by tenants. Different namespaces may have configurations with the same Group or Data ID. ",
type: "java.lang.String"
"sourceType": "com.alibaba.boot.nacos.discovery.properties.NacosDiscoveryProperties",
"name": "nacos.discovery.namespace",
"description": "for configuration isolation by tenants. Different namespaces may have configurations with the same Group or Data ID. ",
"type": "java.lang.String"
},
{
sourceType: "com.alibaba.boot.nacos.discovery.properties.NacosDiscoveryProperties",
name: "nacos.discovery.access-key",
description: "the accesskey of Alibaba Cloud Account",
type: "java.lang.String"
"sourceType": "com.alibaba.boot.nacos.discovery.properties.NacosDiscoveryProperties",
"name": "nacos.discovery.access-key",
"description": "the accesskey of Alibaba Cloud Account",
"type": "java.lang.String"
},
{
sourceType: "com.alibaba.boot.nacos.discovery.properties.NacosDiscoveryProperties",
name: "nacos.discovery.secret-key",
description: "the secretkey of Alibaba Cloud Account",
type: "java.lang.String"
"sourceType": "com.alibaba.boot.nacos.discovery.properties.NacosDiscoveryProperties",
"name": "nacos.discovery.secret-key",
"description": "the secretkey of Alibaba Cloud Account",
"type": "java.lang.String"
},
{
"sourceType": "com.alibaba.boot.nacos.discovery.properties.NacosDiscoveryProperties",
"name": "nacos.discovery.register",
"description": "the service",
"type": "com.alibaba.boot.nacos.discovery.properties.Register"
},
{
"sourceType": "com.alibaba.boot.nacos.discovery.properties.NacosDiscoveryProperties",
"name": "nacos.discovery.auto-register",
"description": "the service",
"type": "java.lang.Boolean"
}
]
}

View File

@ -20,10 +20,14 @@ import java.util.Properties;
import com.alibaba.boot.nacos.discovery.autoconfigure.NacosDiscoveryAutoConfiguration;
import com.alibaba.boot.nacos.discovery.properties.NacosDiscoveryProperties;
import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.annotation.NacosInjected;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.spring.util.NacosBeanUtils;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@ -31,10 +35,6 @@ import org.springframework.context.ApplicationContext;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.annotation.NacosInjected;
import com.alibaba.nacos.spring.util.NacosBeanUtils;
/**
* {@link NacosDiscoveryAutoConfiguration} Test
*
@ -42,46 +42,46 @@ import com.alibaba.nacos.spring.util.NacosBeanUtils;
* @see NacosDiscoveryAutoConfiguration
*/
@RunWith(SpringJUnit4ClassRunner.class)
@TestPropertySource(
properties = {
"nacos.discovery.server-addr=localhost"
}
)
@SpringBootTest(
classes = {NacosDiscoveryAutoConfiguration.class}
)
@TestPropertySource(properties = { "nacos.discovery.server-addr=localhost" })
@SpringBootTest(classes = { NacosDiscoveryAutoConfiguration.class })
public class NacosDiscoveryAutoConfigurationTest {
@Autowired
private NacosDiscoveryProperties nacosDiscoveryProperties;
@Autowired
private NacosDiscoveryProperties nacosDiscoveryProperties;
@Autowired
private ApplicationContext applicationContext;
@Autowired
private ApplicationContext applicationContext;
@NacosInjected
private NamingService namingService;
@NacosInjected
private NamingService namingService;
@Test
public void testNacosDiscovery() {
Assert.assertNotNull(namingService);
Assert.assertNotNull(applicationContext.getBean(NacosBeanUtils.DISCOVERY_GLOBAL_NACOS_PROPERTIES_BEAN_NAME));
Assert.assertEquals("localhost", nacosDiscoveryProperties.getServerAddr());
}
@Test
public void testNacosDiscovery() {
Assert.assertNotNull(namingService);
Assert.assertNotNull(applicationContext
.getBean(NacosBeanUtils.DISCOVERY_GLOBAL_NACOS_PROPERTIES_BEAN_NAME));
Assert.assertEquals("localhost", nacosDiscoveryProperties.getServerAddr());
}
@Test(expected = NoSuchBeanDefinitionException.class)
public void testNacosConfigGlobalBean() {
Assert.assertNull(applicationContext.getBean(NacosBeanUtils.GLOBAL_NACOS_PROPERTIES_BEAN_NAME));
}
@Test(expected = NoSuchBeanDefinitionException.class)
public void testNacosConfigGlobalBean() {
Assert.assertNull(applicationContext
.getBean(NacosBeanUtils.GLOBAL_NACOS_PROPERTIES_BEAN_NAME));
}
@Test(expected = NoSuchBeanDefinitionException.class)
public void testNacosDiscoveryGlobalBean() {
Assert.assertNull(applicationContext.getBean(NacosBeanUtils.CONFIG_GLOBAL_NACOS_PROPERTIES_BEAN_NAME));
}
@Test(expected = NoSuchBeanDefinitionException.class)
public void testNacosDiscoveryGlobalBean() {
Assert.assertNull(applicationContext
.getBean(NacosBeanUtils.CONFIG_GLOBAL_NACOS_PROPERTIES_BEAN_NAME));
}
@Test
public void testNacosGlobalProperties() {
Properties properties = applicationContext.getBean(NacosBeanUtils.DISCOVERY_GLOBAL_NACOS_PROPERTIES_BEAN_NAME, Properties.class);
Assert.assertEquals("localhost", properties.getProperty(PropertyKeyConst.SERVER_ADDR));
}
@Test
public void testNacosGlobalProperties() {
Properties properties = applicationContext.getBean(
NacosBeanUtils.DISCOVERY_GLOBAL_NACOS_PROPERTIES_BEAN_NAME,
Properties.class);
Assert.assertEquals("localhost",
properties.getProperty(PropertyKeyConst.SERVER_ADDR));
}
}

View File

@ -18,7 +18,7 @@
<parent>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-spring-boot-parent</artifactId>
<version>0.9.0</version>
<version>0.1.4</version>
<relativePath>../nacos-spring-boot-parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -18,7 +18,7 @@
<parent>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-spring-boot-parent</artifactId>
<version>0.9.0</version>
<version>0.1.4</version>
<relativePath>../nacos-spring-boot-parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -16,13 +16,14 @@
*/
package com.alibaba.boot.nacos.common;
import com.alibaba.nacos.api.exception.NacosException;
import org.springframework.boot.diagnostics.AbstractFailureAnalyzer;
import org.springframework.boot.diagnostics.FailureAnalysis;
import com.alibaba.nacos.api.exception.NacosException;
/**
* An {@link AbstractFailureAnalyzer} that performs analysis of failures caused by a {@link NacosException}
* An {@link AbstractFailureAnalyzer} that performs analysis of failures caused by a
* {@link NacosException}
*
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
*/
@ -32,32 +33,32 @@ public class NacosFailureAnalyzer extends AbstractFailureAnalyzer<NacosException
protected FailureAnalysis analyze(Throwable rootFailure, NacosException cause) {
StringBuilder description = new StringBuilder();
switch (cause.getErrCode()) {
case NacosException.CLIENT_INVALID_PARAM:
description.append("client error: invalid param");
break;
case NacosException.CLIENT_OVER_THRESHOLD:
description.append("client error: over client threshold");
break;
case NacosException.BAD_GATEWAY:
description.append("server error: bad gateway");
break;
case NacosException.CONFLICT:
description.append("server error: conflict");
break;
case NacosException.INVALID_PARAM:
description.append("server error: invalid param");
break;
case NacosException.NO_RIGHT:
description.append("server error: no right");
break;
case NacosException.OVER_THRESHOLD:
description.append("server error: over threshold");
break;
case NacosException.SERVER_ERROR:
description.append("server error: such as timeout");
break;
default:
description.append("unknown reason");
case NacosException.CLIENT_INVALID_PARAM:
description.append("client error: invalid param");
break;
case NacosException.CLIENT_OVER_THRESHOLD:
description.append("client error: over client threshold");
break;
case NacosException.BAD_GATEWAY:
description.append("server error: bad gateway");
break;
case NacosException.CONFLICT:
description.append("server error: conflict");
break;
case NacosException.INVALID_PARAM:
description.append("server error: invalid param");
break;
case NacosException.NO_RIGHT:
description.append("server error: no right");
break;
case NacosException.OVER_THRESHOLD:
description.append("server error: over threshold");
break;
case NacosException.SERVER_ERROR:
description.append("server error: such as timeout");
break;
default:
description.append("unknown reason");
}
description.append(". ").append(cause.getErrMsg());
String action;

View File

@ -16,6 +16,7 @@
package com.alibaba.boot.nacos.common;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
@ -29,11 +30,13 @@ public class PropertiesUtils {
public static Map<Object, Object> extractSafeProperties(Properties properties) {
Map<Object, Object> result = new HashMap<>();
properties.forEach((key, val) -> {
Enumeration enumeration = properties.propertyNames();
while (enumeration.hasMoreElements()) {
String key = enumeration.nextElement().toString();
if (!PropertyKeyConst.SECRET_KEY.equals(key)) {
result.put(key, val);
result.put(key, properties.get(key));
}
});
}
return result;
}

View File

@ -18,7 +18,7 @@
<parent>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-spring-boot-project</artifactId>
<version>0.9.0</version>
<version>0.1.4</version>
<relativePath>../pom.xml</relativePath>
</parent>
@ -30,13 +30,14 @@
<description>Nacos Spring Boot Parent</description>
<properties>
<java.version>1.8</java.version>
<java.source.version>1.8</java.source.version>
<java.target.version>1.8</java.target.version>
<java.version>1.7</java.version>
<java.source.version>1.7</java.source.version>
<java.target.version>1.7</java.target.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-boot.version>2.0.3.RELEASE</spring-boot.version>
<nacos-spring-context.version>0.3.1</nacos-spring-context.version>
<spring-boot.version>1.4.1.RELEASE</spring-boot.version>
<nacos.version>0.1.0</nacos.version>
<nacos-spring-context.version>0.3.4</nacos-spring-context.version>
<!-- Build args -->
<argline>-server -Xms256m -Xmx512m -XX:PermSize=64m -XX:MaxPermSize=128m -Dfile.encoding=UTF-8
-Djava.net.preferIPv4Stack=true
@ -45,18 +46,30 @@
<!-- Maven plugins -->
<maven-jar-plugin.version>3.0.2</maven-jar-plugin.version>
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
<maven-source-plugin.version>3.0.1</maven-source-plugin.version>
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
<maven-jacoco-plugin.version>0.8.1</maven-jacoco-plugin.version>
<maven-gpg-plugin.version>1.5</maven-gpg-plugin.version>
<apache-rat-plugin.version>0.12</apache-rat-plugin.version>
<maven-release-plugin.version>2.5.3</maven-release-plugin.version>
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
<maven-deploy-plugin.version>2.8.2</maven-deploy-plugin.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
<!-- Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
@ -208,7 +221,7 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<compilerArgument>-proc:none</compilerArgument>
<!--<compilerArgument>-proc:none</compilerArgument>-->
<fork>true</fork>
<source>${java.source.version}</source>
<target>${java.target.version}</target>
@ -252,7 +265,7 @@
<configuration>
<rules>
<requireJavaVersion>
<version>[1.8,)</version>
<version>[1.7,)</version>
</requireJavaVersion>
<requireProperty>
<property>project.name</property>

View File

@ -20,7 +20,7 @@
<parent>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-spring-boot-samples</artifactId>
<version>0.9.0</version>
<version>0.1.4</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -34,6 +34,13 @@
</modules>
<dependencies>
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
<version>1.1.4</version>
</dependency>
<!-- Spring Boot dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
@ -45,6 +52,11 @@
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-config-spring-boot-starter</artifactId>

View File

@ -16,44 +16,41 @@
*/
package com.alibaba.boot.nacos.sample;
import com.alibaba.nacos.api.config.ConfigType;
import com.alibaba.nacos.api.config.annotation.NacosConfigurationProperties;
import java.util.List;
import java.util.Map;
import com.alibaba.nacos.api.config.ConfigType;
import com.alibaba.nacos.api.config.annotation.NacosConfigurationProperties;
/**
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
* @since
* @since 0.1.3
*/
@NacosConfigurationProperties(dataId = "apple", type = ConfigType.YAML)
@NacosConfigurationProperties(dataId = "apple", type = ConfigType.YAML, ignoreNestedProperties = true)
public class Apple {
private List<String> list;
private List<String> list;
private Map<String, List<String>> listMap;
private Map<String, List<String>> listMap;
public List<String> getList() {
return list;
}
public List<String> getList() {
return list;
}
public void setList(List<String> list) {
this.list = list;
}
public void setList(List<String> list) {
this.list = list;
}
public Map<String, List<String>> getListMap() {
return listMap;
}
public Map<String, List<String>> getListMap() {
return listMap;
}
public void setListMap(Map<String, List<String>> listMap) {
this.listMap = listMap;
}
public void setListMap(Map<String, List<String>> listMap) {
this.listMap = listMap;
}
@Override
public String toString() {
return "Apple{" +
"list=" + list +
", listMap=" + listMap +
'}';
}
}
@Override
public String toString() {
return "Apple{" + "list=" + list + ", listMap=" + listMap + '}';
}
}

View File

@ -16,12 +16,11 @@
*/
package com.alibaba.boot.nacos.sample;
import static org.springframework.core.env.StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME;
import static org.springframework.core.env.StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME;
import com.alibaba.nacos.api.config.annotation.NacosConfigListener;
import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource;
import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySources;
import com.alibaba.nacos.api.annotation.NacosProperties;
import com.alibaba.nacos.spring.context.annotation.EnableNacos;
import com.alibaba.nacos.spring.context.annotation.config.EnableNacosConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
@ -29,46 +28,27 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import com.alibaba.nacos.api.annotation.NacosInjected;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.config.annotation.NacosConfigListener;
import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource;
import static org.springframework.core.env.StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME;
import static org.springframework.core.env.StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME;
/**
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
*/
@SpringBootApplication
@NacosPropertySource(
name = "custom",
dataId = ConfigApplication.DATA_ID,
first = true,
before = SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME,
after = SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME
)
@NacosPropertySource(dataId = "people", autoRefreshed = true)
@EnableNacosConfig(globalProperties = @NacosProperties(serverAddr = "192.168.16.104:8848"))
@NacosPropertySources(value = {
@NacosPropertySource(dataId = "people", groupId = "DEVELOP", autoRefreshed = true),
@NacosPropertySource(name = "custom", dataId = ConfigApplication.DATA_ID, groupId = "ALIBABA", first = true, before = SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME, after = SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME) })
public class ConfigApplication {
public static final String content = "dept: Aliware\ngroup: Alibaba";
public static final String DATA_ID = "test";
public static final String DATA_ID = "boot-test";
public static void main(String[] args) {
SpringApplication.run(ConfigApplication.class, args);
}
@Bean
@Order(Ordered.LOWEST_PRECEDENCE)
public CommandLineRunner firstCommandLineRunner() {
return new FirstCommandLineRunner();
}
@Bean
@Order(Ordered.LOWEST_PRECEDENCE - 1)
public CommandLineRunner secondCommandLineRunner() {
@ -80,20 +60,17 @@ public class ConfigApplication {
return new Foo();
}
@Bean
public Apple apple() {
return new Apple();
}
@NacosConfigListener(
dataId = "people",
timeout = 500
)
@NacosConfigListener(dataId = DATA_ID, timeout = 500)
public void onChange(String newContent) throws Exception {
Thread.sleep(100);
System.out.println("onChange : " + newContent);
}
@Bean
public Apple apple() {
return new Apple();
}
@Configuration
@ConditionalOnProperty(prefix = "people", name = "enable", havingValue = "true")
protected static class People {
@ -106,23 +83,6 @@ public class ConfigApplication {
}
public static class FirstCommandLineRunner implements CommandLineRunner {
@NacosInjected
private ConfigService configService;
@Override
public void run(String... args) throws Exception {
if (configService.publishConfig(DATA_ID, Constants.DEFAULT_GROUP, content)) {
Thread.sleep(200);
System.out.println("First runner success: " + configService.getConfig(DATA_ID, Constants.DEFAULT_GROUP, 5000));
}
else {
System.out.println("First runner error: publish config error");
}
}
}
public static class SecondCommandLineRunner implements CommandLineRunner {
@NacosValue("${dept:unknown}")

View File

@ -16,42 +16,36 @@
*/
package com.alibaba.boot.nacos.sample;
import com.alibaba.nacos.api.config.annotation.NacosConfigurationProperties;
/**
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
*/
@NacosConfigurationProperties(
dataId = ConfigApplication.DATA_ID
)
@NacosConfigurationProperties(dataId = ConfigApplication.DATA_ID)
public class Foo {
private String dept;
private String dept;
private String group;
private String group;
public String getDept() {
return dept;
}
public String getDept() {
return dept;
}
public void setDept(String dept) {
this.dept = dept;
}
public void setDept(String dept) {
this.dept = dept;
}
public String getGroup() {
return group;
}
public String getGroup() {
return group;
}
public void setGroup(String group) {
this.group = group;
}
public void setGroup(String group) {
this.group = group;
}
@Override
public String toString() {
return "Foo{" +
"dept='" + dept + '\'' +
", group='" + group + '\'' +
'}';
}
@Override
public String toString() {
return "Foo{" + "dept='" + dept + '\'' + ", group='" + group + '\'' + '}';
}
}

View File

@ -0,0 +1,81 @@
/*
* 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.boot.nacos.sample;
import java.util.Properties;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import javax.annotation.PostConstruct;
import com.alibaba.nacos.api.config.annotation.NacosConfigListener;
import com.alibaba.nacos.spring.util.parse.DefaultPropertiesConfigParse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.logging.LogLevel;
import org.springframework.boot.logging.LoggingSystem;
import org.springframework.stereotype.Service;
/**
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
* @since 0.1.3
*/
@Service
public class PrintLogger {
private static Logger logger = LoggerFactory.getLogger(PrintLogger.class);
private static final String LOGGER_TAG = "logging.level.";
private LoggingSystem loggingSystem = LoggingSystem
.get(PrintLogger.class.getClassLoader());
@NacosConfigListener(dataId = "nacos.log", timeout = 5000)
public void onChange(String newLog) throws Exception {
Properties properties = new DefaultPropertiesConfigParse().parse(newLog);
for (Object t : properties.keySet()) {
String key = String.valueOf(t);
if (key.startsWith(LOGGER_TAG)) {
String strLevel = properties.getProperty(key, "info");
LogLevel level = LogLevel.valueOf(strLevel.toUpperCase());
loggingSystem.setLogLevel(key.replace(LOGGER_TAG, ""), level);
logger.info("{}:{}", key, strLevel);
}
}
}
@PostConstruct
public void printLogger() throws Exception {
Executors.newSingleThreadExecutor().submit(new Runnable() {
@Override
public void run() {
while (true) {
try {
TimeUnit.SECONDS.sleep(5);
}
catch (InterruptedException e) {
e.printStackTrace();
}
logger.info("我是info级别日志");
logger.error("我是error级别日志");
logger.warn("我是warn级别日志");
logger.debug("我是debug级别日志");
}
}
});
}
}

View File

@ -17,34 +17,35 @@
package com.alibaba.boot.nacos.sample;
import com.alibaba.nacos.api.config.annotation.NacosValue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
/**
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
* @since
* @since 0.1.3
*/
@Controller
@RestController
public class TestController {
@NacosValue(value = "${people.enable:bbbbb}", autoRefreshed = true)
private String enable;
@NacosValue(value = "${people.enable:bbbbb}", autoRefreshed = true)
private String enable;
@Autowired
private Apple apple;
@Autowired
private Apple apple;
@RequestMapping()
@ResponseBody
public String testGet() {
return enable;
}
@RequestMapping()
@ResponseBody
public String testGet() {
return enable;
}
@GetMapping("/apple")
public Apple getApplr() {
return apple;
}
@GetMapping("/apple")
public Apple getApple() {
return apple;
}
}

View File

@ -0,0 +1,29 @@
nacos.config.bootstrap.log-enable=true
my.data-id=test
my.environment=DEVELOP
my.group-id=LOG_${my.environment}
nacos.config.data-id=${my.data-id}
nacos.config.group=DEFAULT_GROUP
nacos.config.type=yaml
nacos.config.max-retry=10
nacos.config.config-retry-time=2333
nacos.config.config-long-poll-timeout=46000
nacos.config.enable-remote-sync-config=true
nacos.config.ext-config[0].data-id=nacos.log.test
nacos.config.ext-config[0].group=${my.group-id}
nacos.config.ext-config[0].max-retry=10
nacos.config.ext-config[0].type=properties
nacos.config.ext-config[0].auto-refresh=true
nacos.config.ext-config[0].config-retry-time=2333
nacos.config.ext-config[0].config-long-poll-timeout=46000
nacos.config.ext-config[0].enable-remote-sync-config=true
server.port=10011
security.basic.enabled=false
management.security.enabled=false
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always

View File

@ -0,0 +1,8 @@
nacos.config.ext-config[0].data-id=nacos.log
nacos.config.ext-config[0].group=LOG_DEVELOP
nacos.config.ext-config[0].max-retry=10
nacos.config.ext-config[0].type=properties
nacos.config.ext-config[0].auto-refresh=true
nacos.config.ext-config[0].config-retry-time=2333
nacos.config.ext-config[0].config-long-poll-timeout=46000
nacos.config.ext-config[0].enable-remote-sync-config=true

View File

@ -1,23 +1 @@
nacos.config.server-addr=192.168.16.104:8848
nacos.config.data-id=people
nacos.config.group=DEFAULT_GROUP
nacos.config.type=properties
nacos.config.max-retry=10
nacos.config.config-retry-time=2333
nacos.config.config-long-poll-timeout=46000
nacos.config.bootstrap.enable=true
nacos.config.enable-remote-sync-config=true
nacos.config.ext-config[0].data-id=test
nacos.config.ext-config[0].group=DEFAULT_GROUP
nacos.config.ext-config[0].max-retry=10
nacos.config.ext-config[0].type=yaml
nacos.config.ext-config[0].config-retry-time=2333
nacos.config.ext-config[0].config-long-poll-timeout=46000
nacos.config.ext-config[0].enable-remote-sync-config=true
server.port=10011
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
spring.profiles.active=prod,dev

View File

@ -1,20 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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
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.
-->
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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:nacos="http://nacos.io/schema/nacos"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

View File

@ -20,7 +20,7 @@
<parent>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-spring-boot-samples</artifactId>
<version>0.9.0</version>
<version>0.1.4</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -45,6 +45,11 @@
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-discovery-spring-boot-starter</artifactId>

View File

@ -16,17 +16,8 @@
*/
package com.alibaba.boot.nacos.sample;
import com.alibaba.nacos.api.annotation.NacosInjected;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import java.util.List;
/**
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
@ -34,48 +25,8 @@ import java.util.List;
@SpringBootApplication
public class DiscoveryApplication {
public static void main(String[] args) {
SpringApplication.run(DiscoveryApplication.class, args);
}
@Bean
@Order(Ordered.LOWEST_PRECEDENCE)
public CommandLineRunner firstCommandLineRunner() {
return new FirstCommandLineRunner();
}
@Bean
@Order(Ordered.LOWEST_PRECEDENCE - 1)
public CommandLineRunner secondCommandLineRunner() {
return new SecondCommandLineRunner();
}
public static class FirstCommandLineRunner implements CommandLineRunner {
@NacosInjected
private NamingService namingService;
@Override
public void run(String... args) throws Exception {
System.out.println("start to register");
namingService.registerInstance("test-service", "1.1.1.1", 8080);
}
}
public static class SecondCommandLineRunner implements CommandLineRunner {
@NacosInjected
private NamingService namingService;
@Override
public void run(String... args) throws Exception {
List<Instance> instanceList = namingService.getAllInstances("test-service");
System.out.println("found instance: " + instanceList.size());
instanceList.forEach(instance -> {
System.out.println(instance);
});
}
}
public static void main(String[] args) {
SpringApplication.run(DiscoveryApplication.class, args);
}
}

View File

@ -1,6 +1,17 @@
nacos.discovery.server-addr=localhost:8848
nacos.discovery.server-addr=127.0.0.1:8848
server.port=10012
server.port=10013
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
nacos.discovery.auto-register=true
nacos.discovery.register.ip=1.1.1.1
nacos.discovery.register.port=1
nacos.discovery.register.weight=0.6D
nacos.discovery.register.healthy=false
nacos.discovery.register.enabled=true
nacos.discovery.register.ephemeral=true
nacos.discovery.register.clusterName=SPRING_BOOT
nacos.discovery.register.groupName=BOOT
nacos.discovery.register.metadata.name=liaochuntao
nacos.discovery.register.serviceName=SPRING_BOOT_SERVICE
management.security.enabled=false

View File

@ -20,7 +20,7 @@
<parent>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-spring-boot-parent</artifactId>
<version>0.9.0</version>
<version>0.1.4</version>
<relativePath>../nacos-spring-boot-parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -40,6 +40,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>${maven-deploy-plugin.version}</version>
<configuration>
<skip>true</skip>
</configuration>

15
pom.xml
View File

@ -10,11 +10,12 @@
<properties>
<maven_javadoc_version>3.0.1</maven_javadoc_version>
<maven_surefire_version>2.19.1</maven_surefire_version>
<maven-source-plugin.version>3.1.0</maven-source-plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-spring-boot-project</artifactId>
<version>0.9.0</version>
<version>0.1.4</version>
<packaging>pom</packaging>
@ -54,15 +55,7 @@
</mailingLists>
<developers>
<developer>
<id>Jim</id>
<name>Jim Fang</name>
<email>fangjian0423@gmail.com</email>
<url>https://github.com/fangjian0423</url>
<roles>
<role>Developer</role>
</roles>
</developer>
</developers>
<profiles>
@ -104,7 +97,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<version>${maven-source-plugin.version}</version>
<executions>
<execution>
<id>attach-sources</id>