Compare commits
149 Commits
Author | SHA1 | Date |
---|---|---|
|
08657b90b3 | |
|
eaf15a6e6e | |
|
5a97a9dd6b | |
|
6c29062a1c | |
|
a5aa9f70bb | |
|
82caa209b3 | |
|
71db41f853 | |
|
a5ba72ac01 | |
|
df0f68fcfa | |
|
7144598c21 | |
|
c080c91c15 | |
|
8b2621bc29 | |
|
6b626f364c | |
|
6771d1b311 | |
|
008ae0bce7 | |
|
a9d0ea104a | |
|
c682961079 | |
|
af106fc5da | |
|
3e50f33fe7 | |
|
b1a19f679f | |
|
e5ada95281 | |
|
3ecc302443 | |
|
04e84c2b42 | |
|
02236568b4 | |
|
b6da64e902 | |
|
f0cc777109 | |
|
35e9c3e7c1 | |
|
40035fa032 | |
|
2d257777c2 | |
|
f9efddfb44 | |
|
ca9a90543a | |
|
979c01702d | |
|
a09746f41e | |
|
bfecd49e33 | |
|
cd810f4d25 | |
|
aec14871ca | |
|
9a27a58a00 | |
|
e725f83cdc | |
|
d1575460b8 | |
|
b2649223da | |
|
1ef681c7d6 | |
|
e54e0cdd0d | |
|
a8d6a80dd8 | |
|
dbde2edc24 | |
|
147829ac05 | |
|
a981cc9de9 | |
|
0bf34babc6 | |
|
3e70665970 | |
|
f9c1d281ad | |
|
03ec22f997 | |
|
ed5843c16b | |
|
f401521964 | |
|
1bdd5a2e1a | |
|
b2fb611d4c | |
|
b87a4136f0 | |
|
1ffd948f90 | |
|
d363a2b86d | |
|
1285740ecf | |
|
d9086a3e1c | |
|
6b50bc39df | |
|
437f1e579a | |
|
93641fbbc5 | |
|
446278b767 | |
|
d77d02926d | |
|
39efc09c56 | |
|
8a89b5f1df | |
|
256a35cbd9 | |
|
e9290b86b8 | |
|
9e20b30214 | |
|
6ce80631a7 | |
|
7a762603b7 | |
|
f4a6216bab | |
|
f887cf4870 | |
|
fb58598ff1 | |
|
a759ddac7c | |
|
a993a173ad | |
|
7cb8a79bc4 | |
|
d48c075941 | |
|
9d4ad10765 | |
|
246d3ba599 | |
|
5ef932023c | |
|
499785909f | |
|
e3c30a6d30 | |
|
213755347a | |
|
1d8b73be35 | |
|
fa0f5bf96a | |
|
dbd76289cd | |
|
6663e64f45 | |
|
280b82de59 | |
|
ee232e873c | |
|
101f7cc499 | |
|
e0f7df9601 | |
|
aa2131ecd2 | |
|
f7664c5c85 | |
|
5e09a4f3c4 | |
|
a20b99fe00 | |
|
76ca15d233 | |
|
feb84a307e | |
|
41caa35b53 | |
|
f85fa97d03 | |
|
8f071c1ce1 | |
|
8dac3c52b0 | |
|
4b40b45847 | |
|
49fad25bb1 | |
|
77f981e559 | |
|
1f24267890 | |
|
4f7c0a4cf1 | |
|
934b88888f | |
|
f4fc82fa91 | |
|
dc0b3e99d9 | |
|
aeba4c52a1 | |
|
22bf8d4503 | |
|
1383070e8c | |
|
3eb4f70845 | |
|
f181d782ee | |
|
1d1e018213 | |
|
7b95406a4b | |
|
992e388352 | |
|
c6fb1d43aa | |
|
486b932265 | |
|
9796467878 | |
|
b86128d20e | |
|
e0fc1349a4 | |
|
d03abe7a05 | |
|
4f058183c4 | |
|
4f7dbeabf0 | |
|
bed5ddf121 | |
|
7da27530c9 | |
|
d1ac6d7b44 | |
|
09cfcbb0f4 | |
|
6c42e8ea6b | |
|
f0d48d31c2 | |
|
cff1741940 | |
|
5329d725b3 | |
|
f818a5189d | |
|
367066d03a | |
|
812adfc284 | |
|
4025a41188 | |
|
85fcedb21d | |
|
0c9b4559a3 | |
|
dcc9191b03 | |
|
0ae9561fd6 | |
|
947c94d8ba | |
|
130f077b5b | |
|
40a22a8454 | |
|
a3650ad76a | |
|
87e8db83b4 | |
|
ee65dc9112 | |
|
f952f840bd |
|
@ -29,3 +29,5 @@ hs_err_pid*
|
|||
.settings
|
||||
target
|
||||
|
||||
.DS_Store
|
||||
.flattened-pom.xml
|
||||
|
|
|
@ -0,0 +1,206 @@
|
|||
## Nacos AOT
|
||||
|
||||
### prerequisites
|
||||
|
||||
- GraalVM22.0+ (JDK17)
|
||||
- native-image
|
||||
- Nacos Server
|
||||
|
||||
If you haven't downloaded GraalVM, you can download it from [Download GraalVM](https://www.graalvm.org/downloads/).
|
||||
|
||||
If you don't have a native-image environment, you can configure according to [Native Image](https://www.graalvm.org/latest/reference-manual/native-image/).
|
||||
|
||||
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).
|
||||
|
||||
### Quick Start
|
||||
|
||||
The complete code for this example can be found at: [`nacos-aot-sample`](nacos-spring-boot-samples/nacos-aot-sample)
|
||||
|
||||
1. Because SpringBoot2 does not support aot, you must specify SpringBoot as SpringBoot3 in dependency management:
|
||||
|
||||
```xml
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>3.0.6</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
```
|
||||
|
||||
2. You would add [`nacos-config-spring-boot-starter`](nacos-config-spring-boot-starter) or [`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-config-spring-boot-starter</artifactId>
|
||||
<version>${latest.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.boot</groupId>
|
||||
<artifactId>nacos-discovery-spring-boot-starter</artifactId>
|
||||
<version>${latest.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
```
|
||||
|
||||
3. In order to use the process-aot feature of SpringBoot and more conveniently compile native-image programs, we also need `spring-boot-maven-plugin` and `native-maven-plugin`:
|
||||
|
||||
```xml
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>native</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.graalvm.buildtools</groupId>
|
||||
<artifactId>native-maven-plugin</artifactId>
|
||||
<version>0.9.25</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
|
||||
<mainClass>com.alibaba.boot.nacos.sample.AotApplication</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>process-aot</id>
|
||||
<goals>
|
||||
<goal>process-aot</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
```
|
||||
|
||||
4. You could define some configurations in `application.properties`:
|
||||
|
||||
```properties
|
||||
nacos.config.server-addr=localhost:8848
|
||||
nacos.discovery.server-addr=localhost:8848
|
||||
```
|
||||
|
||||
> `nacos.config.server-addr` and `nacos.discovery.server-addr` attribute configure "\${host}:${port}" of your Nacos Server
|
||||
|
||||
5. You could using `@SpringBootApplication` to annotate main class like normal SpringBoot Application and startup:
|
||||
|
||||
```java
|
||||
@SpringBootApplication
|
||||
@NacosPropertySource(dataId = "example", autoRefreshed = true)
|
||||
public class AotApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(AotApplication.class, args);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Note: `@NacosPropertySource` is used to specify the data-id of the configuration.
|
||||
|
||||
6. Let's try the functions of `@NacosInjected` and `@NacosValue`, for more usage, see [Nacos Spring Project](https://github.com/nacos-group/nacos-spring-project).
|
||||
|
||||
```java
|
||||
@Controller
|
||||
public class AotController {
|
||||
@NacosInjected
|
||||
private ConfigService configService;
|
||||
|
||||
@NacosInjected
|
||||
private NamingService namingService;
|
||||
|
||||
@NacosValue(value = "${flag:false}", autoRefreshed = true)
|
||||
private boolean flag;
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "/config/get", method = GET)
|
||||
public String getConfig() throws NacosException {
|
||||
return configService.getConfig("example", "DEFAULT_GROUP", 5000);
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "/naming/get", method = GET)
|
||||
public List<Instance> getNaming(@RequestParam("serviceName") String serviceName) throws NacosException {
|
||||
return namingService.getAllInstances(serviceName);
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "/flag/get", method = GET)
|
||||
public boolean getFlag() {
|
||||
return flag;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
7. Publish the configuration to the Nacos Server by calling the Nacos Open API, with dataId of example and content of `flag=true`
|
||||
|
||||
```shell
|
||||
curl -X POST "http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=example&group=DEFAULT_GROUP&content=flag=true"
|
||||
```
|
||||
|
||||
8. Enable the tracing agent on the command line with the `java` command from the GraalVM JDK:
|
||||
|
||||
```shell
|
||||
$JAVA_HOME/bin/java -agentlib:native-image-agent=config-output-dir=/path/to/config-dir/ ...
|
||||
```
|
||||
|
||||
Note: For more information about tracing agent, see [Collect Metadata with the Tracing Agent](https://www.graalvm.org/latest/reference-manual/native-image/metadata/AutomaticMetadataCollection/).
|
||||
|
||||
9. Run the java program and follow the steps below to use the program:
|
||||
|
||||
1. Open `localhost:8080/config/get` with a browser, and the browser responds with `flag=true`.
|
||||
2. Open `localhost:8080/flag/get` with a browser, and the browser responds with `true`.
|
||||
3. Publish the configuration to the Nacos Server by calling the Nacos Open API, with dataId of example and content of `flag=false`
|
||||
|
||||
```shell
|
||||
curl -X POST "http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=example&group=DEFAULT_GROUP&content=flag=false"
|
||||
```
|
||||
|
||||
4. Open `localhost:8080/flag/get` with a browser, and the browser responds with `false`.
|
||||
5. Register a service named example with Nacos server by calling Nacos Open API.
|
||||
|
||||
```shell
|
||||
curl -X POST 'http://127.0.0.1:8848/nacos/v1/ns/instance?serviceName=example&ip=127.0.0.1&port=8080'
|
||||
```
|
||||
|
||||
6. Open `localhost:8080/naming/get?serviceName=example` with a browser, and the browser responds with information about the service you just registered.
|
||||
|
||||
10. Close the program and copy the file just generated to the `classpath:META-INF/native-image/` folder, The file path is specified in step 8.
|
||||
|
||||
Note: [`nacos-aot-sample`](nacos-spring-boot-samples/nacos-aot-sample) already includes these files, but you can still use the files you just generated.
|
||||
|
||||
11. Run the following command and you will find the compiled executable program in the `target` folder.
|
||||
|
||||
```shell
|
||||
mvn -DskipTests=true clean package -Pnative
|
||||
```
|
||||
|
||||
12. This executable program is what we want! Run the program and try step 9 again.
|
||||
|
||||
## 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)
|
|
@ -18,10 +18,10 @@ Suppose your Nacos Server is startup, you would add [`nacos-config-spring-boot-s
|
|||
</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.
|
||||
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 and the Spring Boot 3.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
|
||||
```
|
||||
|
@ -98,7 +98,7 @@ Then Configure your endpoint security strategy.
|
|||
management.security.enabled=false
|
||||
```
|
||||
|
||||
* Spring Boot2.x
|
||||
* Spring Boot2.x or Spring Boot3.x
|
||||
|
||||
```properties
|
||||
management.endpoints.web.exposure.include=*
|
||||
|
@ -107,7 +107,7 @@ 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.
|
||||
* Spring Boot2.x or Spring Boot3.x: URL is http://127.0.0.1:10011/actuator/nacos-config.
|
||||
|
||||
## Health Checks
|
||||
|
||||
|
|
|
@ -18,10 +18,10 @@ Suppose your Nacos Server is startup, you would add [`nacos-discovery-spring-boo
|
|||
</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.
|
||||
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 and the Spring Boot 3.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
|
||||
```
|
||||
|
@ -93,7 +93,7 @@ Then Configure your endpoint security strategy.
|
|||
management.security.enabled=false
|
||||
```
|
||||
|
||||
* Spring Boot2.x
|
||||
* Spring Boot2.x or Spring Boot3.x
|
||||
|
||||
```properties
|
||||
management.endpoints.web.exposure.include=*
|
||||
|
@ -102,7 +102,7 @@ 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.
|
||||
* Spring Boot2.x or Spring Boot3.x: URL is http://127.0.0.1:10012/actuator/nacos-discovery.
|
||||
|
||||
## Health Checks
|
||||
|
||||
|
|
16
README.md
16
README.md
|
@ -18,30 +18,33 @@ Nacos Spring Boot Project consist of two parts: `nacos-config-spring-boot` and `
|
|||
|
||||
`nacos-discovery-spring-boot` module is using for Service Discovery, Service Health Check and Dynamic DNS Service.
|
||||
|
||||
Additionally, Nacos Spring Boot Project already supports native-image.
|
||||
|
||||
## Samples
|
||||
|
||||
- [Nacos Config Sample](https://github.com/nacos-group/nacos-spring-boot-project/tree/master/nacos-spring-boot-samples/nacos-config-sample)
|
||||
|
||||
- [Nacos Discovery Sample](https://github.com/nacos-group/nacos-spring-boot-project/tree/master/nacos-spring-boot-samples/nacos-discovery-sample)
|
||||
|
||||
- [Nacos AOT Sample](https://github.com/nacos-group/nacos-spring-boot-project/tree/master/nacos-spring-boot-samples/nacos-aot-sample)
|
||||
|
||||
## Dependencies & Compatibility
|
||||
|
||||
**master branch**
|
||||
**Version: 0.2.x / 2.x.x ( branch master )**
|
||||
|
||||
| Dependencies | Compatibility |
|
||||
| -------------- | ------------- |
|
||||
| Java | 1.8+ |
|
||||
| Spring Boot | 2.0.3.RELEASE |
|
||||
| Nacos-Spring-Context | 0.2.2-RC1 |
|
||||
| Nacos-Spring-Context | 1.1.0 |
|
||||
|
||||
|
||||
**1.x branch**
|
||||
**Version: 0.1.x / 1.x.x ( branch: 1.x )**
|
||||
|
||||
| Dependencies | Compatibility |
|
||||
| -------------- | ------------- |
|
||||
| Java | 1.7+ |
|
||||
| Spring Boot | 1.4.1.RELEASE |
|
||||
| Nacos-Spring-Context | 0.2.2-RC1 |
|
||||
| Nacos-Spring-Context | 1.1.0 |
|
||||
|
||||
|
||||
## Quick Start
|
||||
|
@ -51,9 +54,12 @@ Nacos Spring Boot Project consist of two parts: `nacos-config-spring-boot` and `
|
|||
|
||||
- [Nacos Discovery Quick Start](https://github.com/nacos-group/nacos-spring-boot-project/blob/master/NACOS-DISCOVERY-QUICK-START.md)
|
||||
|
||||
- [Nacos AOT Quick Start](https://github.com/nacos-group/nacos-spring-boot-project/blob/master/NACOS-AOT-QUICK-START.md)
|
||||
|
||||
|
||||
For more information about Nacos Spring, see [Nacos Spring Project](https://github.com/nacos-group/nacos-spring-project).
|
||||
|
||||
For more information about user guide, see [User Guide](https://github.com/nacos-group/nacos-spring-boot-project/wiki/%E7%94%A8%E6%88%B7%E4%BD%BF%E7%94%A8%E6%96%87%E6%A1%A3).
|
||||
## Relative Projects
|
||||
|
||||
* [Alibaba Nacos](https://github.com/alibaba/nacos)
|
||||
|
|
|
@ -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>
|
|
@ -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
|
@ -18,7 +18,7 @@
|
|||
<parent>
|
||||
<artifactId>nacos-spring-boot-parent</artifactId>
|
||||
<groupId>com.alibaba.boot</groupId>
|
||||
<version>0.9.0</version>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../nacos-spring-boot-parent/pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -81,8 +81,20 @@
|
|||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-spring-context</artifactId>
|
||||
<optional>true</optional>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
<version>${nacos.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Test Dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
|
|
@ -16,14 +16,13 @@
|
|||
*/
|
||||
package com.alibaba.boot.nacos.actuate.autoconfigure;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint;
|
||||
import com.alibaba.boot.nacos.actuate.endpoint.NacosConfigEndpoint;
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||
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}
|
||||
*
|
||||
|
@ -35,7 +34,7 @@ public class NacosConfigEndpointAutoConfiguration {
|
|||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnEnabledEndpoint
|
||||
@ConditionalOnAvailableEndpoint
|
||||
public NacosConfigEndpoint nacosEndpoint() {
|
||||
return new NacosConfigEndpoint();
|
||||
}
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
*/
|
||||
package com.alibaba.boot.nacos.actuate.autoconfigure;
|
||||
|
||||
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.endpoint.EndpointAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
|
||||
import org.springframework.boot.actuate.health.HealthIndicator;
|
||||
|
@ -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
|
||||
*
|
||||
|
|
|
@ -16,15 +16,24 @@
|
|||
*/
|
||||
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 com.alibaba.boot.nacos.common.PropertiesUtils;
|
||||
import com.alibaba.boot.nacos.config.NacosConfigConstants;
|
||||
import com.alibaba.nacos.api.config.annotation.NacosConfigListener;
|
||||
import com.alibaba.nacos.api.config.annotation.NacosConfigurationProperties;
|
||||
import com.alibaba.nacos.common.utils.JacksonUtils;
|
||||
import com.alibaba.nacos.spring.context.event.config.NacosConfigMetadataEvent;
|
||||
import com.alibaba.nacos.spring.util.NacosUtils;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
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.annotation.Endpoint;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
|
||||
|
@ -32,15 +41,8 @@ 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;
|
||||
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 static com.alibaba.nacos.spring.util.NacosBeanUtils.CONFIG_GLOBAL_NACOS_PROPERTIES_BEAN_NAME;
|
||||
|
||||
/**
|
||||
* Actuator {@link Endpoint} to expose Nacos Config Meta Data
|
||||
|
@ -55,11 +57,11 @@ public class NacosConfigEndpoint
|
|||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
private Map<String, JSONObject> nacosConfigMetadataMap = new HashMap<>();
|
||||
private Map<String, JsonNode> nacosConfigMetadataMap = new HashMap<>(8);
|
||||
|
||||
@ReadOperation
|
||||
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))) {
|
||||
|
@ -82,37 +84,37 @@ public class NacosConfigEndpoint
|
|||
public void onApplicationEvent(NacosConfigMetadataEvent event) {
|
||||
String key = buildMetadataKey(event);
|
||||
if (StringUtils.isNotEmpty(key) && !nacosConfigMetadataMap.containsKey(key)) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("groupId", event.getGroupId());
|
||||
jsonObject.put("dataId", event.getDataId());
|
||||
ObjectNode jsonNode = JacksonUtils.createEmptyJsonNode();
|
||||
jsonNode.put("groupId", event.getGroupId());
|
||||
jsonNode.put("dataId", event.getDataId());
|
||||
if (ClassUtils.isAssignable(event.getSource().getClass(),
|
||||
AnnotationMetadata.class)) {
|
||||
jsonObject.put("origin", "NacosPropertySource");
|
||||
jsonObject.put("target",
|
||||
jsonNode.put("origin", "NacosPropertySource");
|
||||
jsonNode.put("target",
|
||||
((AnnotationMetadata) event.getSource()).getClassName());
|
||||
}
|
||||
else if (ClassUtils.isAssignable(event.getSource().getClass(),
|
||||
NacosConfigListener.class)) {
|
||||
jsonObject.put("origin", "NacosConfigListener");
|
||||
jsonNode.put("origin", "NacosConfigListener");
|
||||
Method configListenerMethod = (Method) event.getAnnotatedElement();
|
||||
jsonObject.put("target",
|
||||
jsonNode.put("target",
|
||||
configListenerMethod.getDeclaringClass().getName() + ":"
|
||||
+ configListenerMethod.toString());
|
||||
}
|
||||
else if (ClassUtils.isAssignable(event.getSource().getClass(),
|
||||
NacosConfigurationProperties.class)) {
|
||||
jsonObject.put("origin", "NacosConfigurationProperties");
|
||||
jsonObject.put("target", event.getBeanType().getName());
|
||||
jsonNode.put("origin", "NacosConfigurationProperties");
|
||||
jsonNode.put("target", event.getBeanType().getName());
|
||||
}
|
||||
else if (ClassUtils.isAssignable(event.getSource().getClass(),
|
||||
Element.class)) {
|
||||
jsonObject.put("origin", "NacosPropertySource");
|
||||
jsonObject.put("target", event.getXmlResource().toString());
|
||||
jsonNode.put("origin", "NacosPropertySource");
|
||||
jsonNode.put("target", event.getXmlResource().toString());
|
||||
}
|
||||
else {
|
||||
throw new RuntimeException("unknown NacosConfigMetadataEvent");
|
||||
}
|
||||
nacosConfigMetadataMap.put(key, jsonObject);
|
||||
nacosConfigMetadataMap.put(key, jsonNode);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,19 +18,19 @@ package com.alibaba.boot.nacos.actuate.health;
|
|||
|
||||
import java.util.Properties;
|
||||
|
||||
import com.alibaba.boot.nacos.common.PropertiesUtils;
|
||||
import com.alibaba.nacos.api.config.ConfigService;
|
||||
import com.alibaba.nacos.common.utils.JacksonUtils;
|
||||
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.config.ConfigService;
|
||||
import com.alibaba.nacos.spring.factory.CacheableEventPublishingNacosServiceFactory;
|
||||
import com.alibaba.nacos.spring.factory.NacosServiceFactory;
|
||||
import com.alibaba.nacos.spring.metadata.NacosServiceMetaData;
|
||||
|
||||
/**
|
||||
* Nacos Config {@link HealthIndicator}
|
||||
*
|
||||
|
@ -38,6 +38,7 @@ import com.alibaba.nacos.spring.metadata.NacosServiceMetaData;
|
|||
* @see HealthIndicator
|
||||
*/
|
||||
public class NacosConfigHealthIndicator extends AbstractHealthIndicator {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
|
@ -46,13 +47,14 @@ 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;
|
||||
Properties properties = nacosServiceMetaData.getProperties();
|
||||
builder.withDetail(
|
||||
JSON.toJSONString(
|
||||
JacksonUtils.toJson(
|
||||
PropertiesUtils.extractSafeProperties(properties)),
|
||||
configService.getServerStatus());
|
||||
}
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
[
|
||||
{
|
||||
"name": "org.springframework.core.env.ConfigurableEnvironment",
|
||||
"allDeclaredMethods": true,
|
||||
"allDeclaredFields": true,
|
||||
"allDeclaredConstructors": true,
|
||||
"allPublicMethods": true,
|
||||
"allPublicFields": true,
|
||||
"allPublicConstructors": true
|
||||
},
|
||||
{
|
||||
"name": "java.util.Properties",
|
||||
"allDeclaredMethods": true,
|
||||
"allDeclaredFields": true,
|
||||
"allDeclaredConstructors": true,
|
||||
"allPublicMethods": true,
|
||||
"allPublicFields": true,
|
||||
"allPublicConstructors": true
|
||||
},
|
||||
{
|
||||
"name": "org.springframework.core.type.AnnotationMetadata",
|
||||
"allDeclaredMethods": true,
|
||||
"allDeclaredFields": true,
|
||||
"allDeclaredConstructors": true,
|
||||
"allPublicMethods": true,
|
||||
"allPublicFields": true,
|
||||
"allPublicConstructors": true
|
||||
},
|
||||
{
|
||||
"name": "com.alibaba.nacos.api.config.annotation.NacosConfigListener",
|
||||
"allDeclaredMethods": true,
|
||||
"allDeclaredFields": true,
|
||||
"allDeclaredConstructors": true,
|
||||
"allPublicMethods": true,
|
||||
"allPublicFields": true,
|
||||
"allPublicConstructors": true
|
||||
},
|
||||
{
|
||||
"name": "com.alibaba.nacos.api.config.annotation.NacosConfigurationProperties",
|
||||
"allDeclaredMethods": true,
|
||||
"allDeclaredFields": true,
|
||||
"allDeclaredConstructors": true,
|
||||
"allPublicMethods": true,
|
||||
"allPublicFields": true,
|
||||
"allPublicConstructors": true
|
||||
},
|
||||
{
|
||||
"name": "org.w3c.dom.Element",
|
||||
"allDeclaredMethods": true,
|
||||
"allDeclaredFields": true,
|
||||
"allDeclaredConstructors": true,
|
||||
"allPublicMethods": true,
|
||||
"allPublicFields": true,
|
||||
"allPublicConstructors": true
|
||||
}
|
||||
]
|
|
@ -0,0 +1,2 @@
|
|||
com.alibaba.boot.nacos.actuate.autoconfigure.NacosConfigEndpointAutoConfiguration
|
||||
com.alibaba.boot.nacos.actuate.autoconfigure.NacosConfigHealthIndicatorAutoConfiguration
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
*
|
||||
* * 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.actuate.autoconfigure;
|
||||
|
||||
import com.alibaba.boot.nacos.actuate.endpoint.NacosConfigEndpoint;
|
||||
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.context.ApplicationContext;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* {@link NacosConfigEndpointAutoConfiguration} Test
|
||||
* @ClassName: NacosConfigEndpointAutoConfigurationTest
|
||||
* @Author: SuperZ1999
|
||||
* @Date: 2023/9/28
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = {NacosConfigEndpointAutoConfiguration.class})
|
||||
@TestPropertySource(properties = {
|
||||
"management.endpoints.web.exposure.include=nacos-config"
|
||||
})
|
||||
public class NacosConfigEndpointAutoConfigurationTest {
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void testNacosConfigEndpointBean() {
|
||||
Assert.assertNotNull(context.getBean(NacosConfigEndpoint.class));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
*
|
||||
* * Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* * contributor license agreements. See the NOTICE file distributed with
|
||||
* * this work for additional information regarding copyright ownership.
|
||||
* * The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* * (the "License"); you may not use this file except in compliance with
|
||||
* * the License. You may obtain a copy of the License at
|
||||
* *
|
||||
* * http://www.apache.org/licenses/LICENSE-2.0
|
||||
* *
|
||||
* * Unless required by applicable law or agreed to in writing, software
|
||||
* * distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* * See the License for the specific language governing permissions and
|
||||
* * limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.alibaba.boot.nacos.actuate.autoconfigure;
|
||||
|
||||
import com.alibaba.boot.nacos.actuate.health.NacosConfigHealthIndicator;
|
||||
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.context.ApplicationContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* {@link NacosConfigHealthIndicatorAutoConfiguration} Test
|
||||
* @ClassName: NacosConfigHealthIndicatorAutoConfigurationTest
|
||||
* @Author: SuperZ1999
|
||||
* @Date: 2023/9/28
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = {NacosConfigHealthIndicatorAutoConfiguration.class})
|
||||
public class NacosConfigHealthIndicatorAutoConfigurationTest {
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void testNacosConfigHealthIndicatorBean() {
|
||||
Assert.assertNotNull(context.getBean(NacosConfigHealthIndicator.class));
|
||||
}
|
||||
}
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
<parent>
|
||||
<groupId>com.alibaba.boot</groupId>
|
||||
<artifactId>nacos-spring-boot-parent</artifactId>
|
||||
<version>0.9.0</version>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../nacos-spring-boot-parent</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -27,6 +27,18 @@
|
|||
<packaging>jar</packaging>
|
||||
<name>Nacos Config Spring Boot AutoConfigure</name>
|
||||
<description>Nacos Config Spring Boot AutoConfigure</description>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
<dependencies>
|
||||
|
@ -54,11 +66,30 @@
|
|||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-spring-context</artifactId>
|
||||
<optional>true</optional>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
<version>${nacos.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.boot</groupId>
|
||||
<artifactId>nacos-spring-boot-base</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.boot</groupId>
|
||||
<artifactId>nacos-spring-boot-base</artifactId>
|
||||
<artifactId>nacos-spring-boot-aot</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
|
|
|
@ -29,8 +29,10 @@ public interface NacosConfigConstants {
|
|||
|
||||
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";
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
|
||||
* @since 0.2.3
|
||||
*/
|
||||
public class NacosBootConfigException extends RuntimeException {
|
||||
|
||||
public NacosBootConfigException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public NacosBootConfigException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
|
@ -16,105 +16,89 @@
|
|||
*/
|
||||
package com.alibaba.boot.nacos.config.autoconfigure;
|
||||
|
||||
import com.alibaba.boot.nacos.config.NacosConfigConstants;
|
||||
import java.util.Properties;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.alibaba.boot.nacos.config.properties.NacosConfigProperties;
|
||||
import com.alibaba.boot.nacos.config.util.NacosConfigLoader;
|
||||
import com.alibaba.boot.nacos.config.util.NacosConfigLoaderFactory;
|
||||
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.api.config.ConfigService;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.client.config.utils.SnapShotSwitch;
|
||||
import com.alibaba.nacos.spring.factory.CacheableEventPublishingNacosServiceFactory;
|
||||
import com.alibaba.nacos.spring.util.config.NacosConfigLoader;
|
||||
import com.alibaba.nacos.spring.util.NacosBeanUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
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
|
||||
* @since 0.2.2
|
||||
*/
|
||||
public class NacosConfigApplicationContextInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
|
||||
public class NacosConfigApplicationContextInitializer
|
||||
implements ApplicationContextInitializer<ConfigurableApplicationContext> {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(NacosConfigApplicationContextInitializer.class);
|
||||
private final Logger logger = LoggerFactory
|
||||
.getLogger(NacosConfigApplicationContextInitializer.class);
|
||||
private final NacosConfigEnvironmentProcessor processor;
|
||||
private final CacheableEventPublishingNacosServiceFactory singleton = CacheableEventPublishingNacosServiceFactory
|
||||
.getSingleton();
|
||||
private final Function<Properties, ConfigService> builder = properties -> {
|
||||
try {
|
||||
return singleton.createConfigService(properties);
|
||||
}
|
||||
catch (NacosException e) {
|
||||
throw new NacosBootConfigException(
|
||||
"ConfigService can't be created with properties : " + properties, e);
|
||||
}
|
||||
};
|
||||
private ConfigurableEnvironment environment;
|
||||
private NacosConfigProperties nacosConfigProperties;
|
||||
|
||||
private ConfigurableEnvironment environment;
|
||||
public NacosConfigApplicationContextInitializer(
|
||||
NacosConfigEnvironmentProcessor configEnvironmentProcessor) {
|
||||
this.processor = configEnvironmentProcessor;
|
||||
}
|
||||
|
||||
private NacosConfigProperties nacosConfigProperties;
|
||||
@Override
|
||||
public void initialize(ConfigurableApplicationContext context) {
|
||||
singleton.setApplicationContext(context);
|
||||
environment = context.getEnvironment();
|
||||
nacosConfigProperties = NacosConfigPropertiesUtils
|
||||
.buildNacosConfigProperties(environment);
|
||||
final NacosConfigLoader configLoader = NacosConfigLoaderFactory.getSingleton(builder);
|
||||
|
||||
private NacosConfigLoader nacosConfigLoader;
|
||||
if (!processor.snapshotEnable()){
|
||||
SnapShotSwitch.setIsSnapShot(false);
|
||||
}
|
||||
|
||||
@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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!enable()) {
|
||||
logger.info("[Nacos Config Boot] : The preload configuration is not enabled");
|
||||
}
|
||||
else {
|
||||
|
||||
private boolean isEnable() {
|
||||
return Boolean.valueOf(environment.getProperty(NacosConfigConstants.NACOS_BOOTSTRAP, "false"));
|
||||
}
|
||||
// If it opens the log level loading directly will cache
|
||||
// DeferNacosPropertySource release
|
||||
|
||||
private Properties buildGlobalNacosProperties() {
|
||||
return NacosPropertiesBuilder.buildNacosProperties(nacosConfigProperties.getServerAddr(), nacosConfigProperties.getNamespace(),
|
||||
nacosConfigProperties.getEndpoint(), nacosConfigProperties.getSecretKey(), nacosConfigProperties.getAccessKey(),
|
||||
nacosConfigProperties.getConfigLongPollTimeout(), nacosConfigProperties.getConfigRetryTime(),
|
||||
nacosConfigProperties.getMaxRetry(), nacosConfigProperties.isEnableRemoteSyncConfig());
|
||||
}
|
||||
if (processor.enable()) {
|
||||
processor.publishDeferService(context);
|
||||
configLoader
|
||||
.addListenerIfAutoRefreshed(processor.getDeferPropertySources());
|
||||
}
|
||||
else {
|
||||
configLoader.loadConfig(environment, nacosConfigProperties);
|
||||
configLoader.addListenerIfAutoRefreshed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 boolean enable() {
|
||||
return processor.enable() || nacosConfigProperties.getBootstrap().isEnable();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,19 +16,20 @@
|
|||
*/
|
||||
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.aot.context.EnableNacosConfigAotProcessor;
|
||||
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}
|
||||
*
|
||||
|
@ -38,7 +39,7 @@ import org.springframework.context.annotation.Import;
|
|||
@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})
|
||||
@Import(value = { NacosConfigBootBeanDefinitionRegistrar.class, EnableNacosConfigAotProcessor.class })
|
||||
@EnableNacosConfig
|
||||
public class NacosConfigAutoConfiguration {
|
||||
|
||||
|
|
|
@ -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.2.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) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
* 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 java.util.function.Function;
|
||||
|
||||
import com.alibaba.boot.nacos.config.properties.NacosConfigProperties;
|
||||
import com.alibaba.boot.nacos.config.util.NacosConfigLoader;
|
||||
import com.alibaba.boot.nacos.config.util.NacosConfigLoaderFactory;
|
||||
import com.alibaba.boot.nacos.config.util.NacosConfigPropertiesUtils;
|
||||
import com.alibaba.boot.nacos.config.util.log.LogAutoFreshProcess;
|
||||
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;
|
||||
|
||||
/**
|
||||
* In the Context to create premise before loading the log configuration information
|
||||
*
|
||||
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
|
||||
* @since 0.2.3
|
||||
*/
|
||||
public class NacosConfigEnvironmentProcessor
|
||||
implements EnvironmentPostProcessor, Ordered {
|
||||
|
||||
private final Logger logger = LoggerFactory
|
||||
.getLogger(NacosConfigEnvironmentProcessor.class);
|
||||
private final CacheableEventPublishingNacosServiceFactory nacosServiceFactory = CacheableEventPublishingNacosServiceFactory
|
||||
.getSingleton();
|
||||
private final Map<String, ConfigService> serviceCache = new HashMap<>(8);
|
||||
private final LinkedList<NacosConfigLoader.DeferNacosPropertySource> deferPropertySources = new LinkedList<>();
|
||||
|
||||
private NacosConfigProperties nacosConfigProperties;
|
||||
|
||||
// Because ApplicationContext has not been injected at preload time, need to manually
|
||||
// cache the created Service to prevent duplicate creation
|
||||
private final Function<Properties, ConfigService> builder = properties -> {
|
||||
try {
|
||||
final String key = NacosUtils.identify(properties);
|
||||
if (serviceCache.containsKey(key)) {
|
||||
return serviceCache.get(key);
|
||||
}
|
||||
final ConfigService configService = NacosFactory
|
||||
.createConfigService(properties);
|
||||
serviceCache.put(key, configService);
|
||||
return nacosServiceFactory.deferCreateService(configService, properties);
|
||||
}
|
||||
catch (NacosException e) {
|
||||
throw new NacosBootConfigException(
|
||||
"ConfigService can't be created with properties : " + properties, e);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment,
|
||||
SpringApplication application) {
|
||||
application.addInitializers(new NacosConfigApplicationContextInitializer(this));
|
||||
nacosConfigProperties = NacosConfigPropertiesUtils
|
||||
.buildNacosConfigProperties(environment);
|
||||
if (enable()) {
|
||||
System.out.println(
|
||||
"[Nacos Config Boot] : The preload log configuration is enabled");
|
||||
NacosConfigLoader nacosConfigLoader = NacosConfigLoaderFactory.getSingleton(builder);
|
||||
loadConfig(nacosConfigLoader, environment, nacosConfigProperties);
|
||||
LogAutoFreshProcess.build(environment, nacosConfigProperties, nacosConfigLoader, builder).process();
|
||||
}
|
||||
}
|
||||
|
||||
private void loadConfig(NacosConfigLoader configLoader, ConfigurableEnvironment environment, NacosConfigProperties nacosConfigProperties) {
|
||||
configLoader.loadConfig(environment, nacosConfigProperties);
|
||||
// set defer NacosPropertySource
|
||||
deferPropertySources.addAll(configLoader.getNacosPropertySources());
|
||||
}
|
||||
|
||||
boolean enable() {
|
||||
return nacosConfigProperties != null
|
||||
&& nacosConfigProperties.getBootstrap().isLogEnable();
|
||||
}
|
||||
|
||||
boolean snapshotEnable() {
|
||||
return nacosConfigProperties != null
|
||||
&& nacosConfigProperties.getBootstrap().isSnapshotEnable();
|
||||
}
|
||||
|
||||
LinkedList<NacosConfigLoader.DeferNacosPropertySource> getDeferPropertySources() {
|
||||
return deferPropertySources;
|
||||
}
|
||||
|
||||
// Do not set the minimum priority for future expansion needs
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return Ordered.LOWEST_PRECEDENCE - 5;
|
||||
}
|
||||
|
||||
void publishDeferService(ApplicationContext context) {
|
||||
try {
|
||||
nacosServiceFactory.publishDeferService(context);
|
||||
serviceCache.clear();
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.error("publish defer ConfigService has some error", e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,64 +16,74 @@
|
|||
*/
|
||||
package com.alibaba.boot.nacos.config.binder;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
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 com.alibaba.nacos.spring.util.ObjectUtils;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
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.core.env.StandardEnvironment;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
|
||||
* @since
|
||||
* @since 0.2.2
|
||||
*/
|
||||
public class NacosBootConfigurationPropertiesBinder extends NacosConfigurationPropertiesBinder {
|
||||
public class NacosBootConfigurationPropertiesBinder
|
||||
extends NacosConfigurationPropertiesBinder {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(NacosBootConfigurationPropertiesBinder.class);
|
||||
private final ConfigurableApplicationContext applicationContext;
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
private ConfigurationBeanFactoryMetadata beanFactoryMetadata;
|
||||
private final StandardEnvironment environment = new StandardEnvironment();
|
||||
|
||||
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.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doBind(Object bean, String beanName, String dataId, String groupId,
|
||||
NacosConfigurationProperties properties, String content, ConfigService configService) {
|
||||
@Override
|
||||
protected void doBind(Object bean, String beanName, String dataId, String groupId,
|
||||
String configType, NacosConfigurationProperties properties, String content,
|
||||
ConfigService configService) {
|
||||
synchronized (this) {
|
||||
String name = "nacos-bootstrap-" + beanName;
|
||||
NacosPropertySource propertySource = new NacosPropertySource(dataId, groupId, name, content, configType);
|
||||
environment.getPropertySources().addLast(propertySource);
|
||||
ObjectUtils.cleanMapOrCollectionField(bean);
|
||||
Binder binder = Binder.get(environment);
|
||||
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);
|
||||
environment.getPropertySources().remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
private ResolvableType getBeanType(Object bean, String beanName) {
|
||||
Method factoryMethod = findFactoryMethod(beanName);
|
||||
if (factoryMethod != null) {
|
||||
return ResolvableType.forMethodReturnType(factoryMethod);
|
||||
}
|
||||
return ResolvableType.forClass(bean.getClass());
|
||||
}
|
||||
|
||||
public Method findFactoryMethod(String beanName) {
|
||||
ConfigurableListableBeanFactory beanFactory = this.applicationContext.getBeanFactory();
|
||||
if (beanFactory.containsBeanDefinition(beanName)) {
|
||||
BeanDefinition beanDefinition = beanFactory.getMergedBeanDefinition(beanName);
|
||||
if (beanDefinition instanceof RootBeanDefinition) {
|
||||
return ((RootBeanDefinition) beanDefinition).getResolvedFactoryMethod();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed 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
|
||||
*
|
||||
* https://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.logging;
|
||||
|
||||
|
||||
import com.alibaba.boot.nacos.config.properties.NacosConfigProperties;
|
||||
import com.alibaba.boot.nacos.config.util.NacosConfigPropertiesUtils;
|
||||
import com.alibaba.nacos.client.logging.NacosLogging;
|
||||
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.event.GenericApplicationListener;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.ResolvableType;
|
||||
|
||||
/**
|
||||
* Reload nacos log configuration file, after
|
||||
* {@link org.springframework.boot.context.logging.LoggingApplicationListener}.
|
||||
*
|
||||
* @author mai.jh
|
||||
*/
|
||||
public class NacosLoggingListener implements GenericApplicationListener {
|
||||
|
||||
@Override
|
||||
public boolean supportsEventType(ResolvableType resolvableType) {
|
||||
Class<?> type = resolvableType.getRawClass();
|
||||
if (type != null) {
|
||||
return ApplicationEnvironmentPreparedEvent.class.isAssignableFrom(type);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsSourceType(Class<?> aClass) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationEvent applicationEvent) {
|
||||
//If the managed log is enabled, load your own log configuration after loading the user log configuration
|
||||
ApplicationEnvironmentPreparedEvent applicationEnvironmentPreparedEvent = (ApplicationEnvironmentPreparedEvent) applicationEvent;
|
||||
NacosConfigProperties nacosConfigProperties = NacosConfigPropertiesUtils.buildNacosConfigProperties(
|
||||
applicationEnvironmentPreparedEvent.getEnvironment());
|
||||
if(nacosConfigProperties.getBootstrap().isLogEnable()){
|
||||
NacosLogging.getInstance().loadConfiguration();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return Ordered.HIGHEST_PRECEDENCE + 21;
|
||||
}
|
||||
|
||||
}
|
|
@ -16,15 +16,18 @@
|
|||
|
||||
package com.alibaba.boot.nacos.config.properties;
|
||||
|
||||
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 java.util.Objects;
|
||||
|
||||
import com.alibaba.boot.nacos.config.NacosConfigConstants;
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.config.ConfigType;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
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 +37,491 @@ 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 = ConfigType.PROPERTIES;
|
||||
|
||||
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;
|
||||
}
|
||||
private String username;
|
||||
|
||||
public String getContextPath() {
|
||||
return contextPath;
|
||||
}
|
||||
private String password;
|
||||
|
||||
public void setContextPath(String contextPath) {
|
||||
this.contextPath = contextPath;
|
||||
}
|
||||
private boolean remoteFirst = false;
|
||||
|
||||
public String getEncode() {
|
||||
return encode;
|
||||
}
|
||||
@JsonIgnore
|
||||
private List<Config> extConfig = new ArrayList<>();
|
||||
|
||||
public void setEncode(String encode) {
|
||||
this.encode = encode;
|
||||
}
|
||||
@NestedConfigurationProperty
|
||||
private Bootstrap bootstrap = new Bootstrap();
|
||||
|
||||
public String getEndpoint() {
|
||||
return endpoint;
|
||||
}
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setEndpoint(String endpoint) {
|
||||
this.endpoint = endpoint;
|
||||
}
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getNamespace() {
|
||||
return namespace;
|
||||
}
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setNamespace(String namespace) {
|
||||
this.namespace = namespace;
|
||||
}
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getAccessKey() {
|
||||
return accessKey;
|
||||
}
|
||||
public String getServerAddr() {
|
||||
return serverAddr;
|
||||
}
|
||||
|
||||
public void setAccessKey(String accessKey) {
|
||||
this.accessKey = accessKey;
|
||||
}
|
||||
public void setServerAddr(String serverAddr) {
|
||||
Assert.notNull(serverAddr, "nacos config server-addr must not be null");
|
||||
this.serverAddr = serverAddr;
|
||||
}
|
||||
|
||||
public String getSecretKey() {
|
||||
return secretKey;
|
||||
}
|
||||
public String getContextPath() {
|
||||
return contextPath;
|
||||
}
|
||||
|
||||
public void setSecretKey(String secretKey) {
|
||||
this.secretKey = secretKey;
|
||||
}
|
||||
public void setContextPath(String contextPath) {
|
||||
this.contextPath = contextPath;
|
||||
}
|
||||
|
||||
public boolean isAutoRefresh() {
|
||||
return autoRefresh;
|
||||
}
|
||||
public String getEncode() {
|
||||
return encode;
|
||||
}
|
||||
|
||||
public void setAutoRefresh(boolean autoRefresh) {
|
||||
this.autoRefresh = autoRefresh;
|
||||
}
|
||||
public void setEncode(String encode) {
|
||||
this.encode = encode;
|
||||
}
|
||||
|
||||
public String getDataId() {
|
||||
return dataId;
|
||||
}
|
||||
public String getEndpoint() {
|
||||
return endpoint;
|
||||
}
|
||||
|
||||
public void setDataId(String dataId) {
|
||||
this.dataId = dataId;
|
||||
}
|
||||
public void setEndpoint(String endpoint) {
|
||||
this.endpoint = endpoint;
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
public String getNamespace() {
|
||||
return namespace;
|
||||
}
|
||||
|
||||
public void setGroup(String group) {
|
||||
this.group = group;
|
||||
}
|
||||
public void setNamespace(String namespace) {
|
||||
this.namespace = namespace;
|
||||
}
|
||||
|
||||
public ConfigType getType() {
|
||||
return type;
|
||||
}
|
||||
public String getAccessKey() {
|
||||
return accessKey;
|
||||
}
|
||||
|
||||
public void setType(ConfigType type) {
|
||||
this.type = type;
|
||||
}
|
||||
public void setAccessKey(String accessKey) {
|
||||
this.accessKey = accessKey;
|
||||
}
|
||||
|
||||
public String getMaxRetry() {
|
||||
return maxRetry;
|
||||
}
|
||||
public String getSecretKey() {
|
||||
return secretKey;
|
||||
}
|
||||
|
||||
public void setMaxRetry(String maxRetry) {
|
||||
this.maxRetry = maxRetry;
|
||||
}
|
||||
public void setSecretKey(String secretKey) {
|
||||
this.secretKey = secretKey;
|
||||
}
|
||||
|
||||
public String getConfigLongPollTimeout() {
|
||||
return configLongPollTimeout;
|
||||
}
|
||||
public String getRamRoleName() {
|
||||
return ramRoleName;
|
||||
}
|
||||
|
||||
public void setConfigLongPollTimeout(String configLongPollTimeout) {
|
||||
this.configLongPollTimeout = configLongPollTimeout;
|
||||
}
|
||||
public void setRamRoleName(String ramRoleName) {
|
||||
this.ramRoleName = ramRoleName;
|
||||
}
|
||||
|
||||
public String getConfigRetryTime() {
|
||||
return configRetryTime;
|
||||
}
|
||||
public boolean isAutoRefresh() {
|
||||
return autoRefresh;
|
||||
}
|
||||
|
||||
public void setConfigRetryTime(String configRetryTime) {
|
||||
this.configRetryTime = configRetryTime;
|
||||
}
|
||||
public void setAutoRefresh(boolean autoRefresh) {
|
||||
this.autoRefresh = autoRefresh;
|
||||
}
|
||||
|
||||
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 isEnableRemoteSyncConfig() {
|
||||
return enableRemoteSyncConfig;
|
||||
}
|
||||
|
||||
public void setEnableRemoteSyncConfig(boolean enableRemoteSyncConfig) {
|
||||
this.enableRemoteSyncConfig = enableRemoteSyncConfig;
|
||||
}
|
||||
|
||||
public boolean isRemoteFirst() {
|
||||
return remoteFirst;
|
||||
}
|
||||
|
||||
public void setRemoteFirst(boolean remoteFirst) {
|
||||
this.remoteFirst = remoteFirst;
|
||||
}
|
||||
|
||||
public List<Config> getExtConfig() {
|
||||
return extConfig;
|
||||
}
|
||||
|
||||
public boolean isEnableRemoteSyncConfig() {
|
||||
return enableRemoteSyncConfig;
|
||||
}
|
||||
public void setExtConfig(List<Config> extConfig) {
|
||||
this.extConfig = extConfig;
|
||||
}
|
||||
|
||||
public void setEnableRemoteSyncConfig(boolean enableRemoteSyncConfig) {
|
||||
this.enableRemoteSyncConfig = enableRemoteSyncConfig;
|
||||
}
|
||||
public Bootstrap getBootstrap() {
|
||||
return bootstrap;
|
||||
}
|
||||
|
||||
public List<Config> getExtConfig() {
|
||||
return extConfig;
|
||||
}
|
||||
public void setBootstrap(Bootstrap bootstrap) {
|
||||
this.bootstrap = bootstrap;
|
||||
}
|
||||
|
||||
public void setExtConfig(List<Config> extConfig) {
|
||||
this.extConfig = extConfig;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuffer sb = new StringBuffer("NacosConfigProperties{");
|
||||
sb.append("serverAddr='").append(serverAddr).append('\'');
|
||||
sb.append(", contextPath='").append(contextPath).append('\'');
|
||||
sb.append(", encode='").append(encode).append('\'');
|
||||
sb.append(", endpoint='").append(endpoint).append('\'');
|
||||
sb.append(", namespace='").append(namespace).append('\'');
|
||||
sb.append(", accessKey='").append(Objects.isNull(accessKey) ? null : "******").append('\'');
|
||||
sb.append(", secretKey='").append(Objects.isNull(secretKey) ? null : "******").append('\'');
|
||||
sb.append(", ramRoleName='").append(ramRoleName).append('\'');
|
||||
sb.append(", autoRefresh=").append(autoRefresh);
|
||||
sb.append(", dataId='").append(dataId).append('\'');
|
||||
sb.append(", dataIds='").append(dataIds).append('\'');
|
||||
sb.append(", group='").append(group).append('\'');
|
||||
sb.append(", type=").append(type);
|
||||
sb.append(", maxRetry='").append(maxRetry).append('\'');
|
||||
sb.append(", configLongPollTimeout='").append(configLongPollTimeout).append('\'');
|
||||
sb.append(", configRetryTime='").append(configRetryTime).append('\'');
|
||||
sb.append(", enableRemoteSyncConfig=").append(enableRemoteSyncConfig);
|
||||
sb.append(", extConfig=").append(extConfig);
|
||||
sb.append(", bootstrap=").append(bootstrap);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static class Config {
|
||||
public static class Bootstrap {
|
||||
|
||||
private String serverAddr;
|
||||
private boolean enable;
|
||||
|
||||
private String endpoint;
|
||||
private boolean logEnable;
|
||||
|
||||
private String namespace;
|
||||
private boolean snapshotEnable;
|
||||
|
||||
private String accessKey;
|
||||
public boolean isEnable() {
|
||||
return enable;
|
||||
}
|
||||
|
||||
private String secretKey;
|
||||
public void setEnable(boolean enable) {
|
||||
this.enable = enable;
|
||||
}
|
||||
|
||||
private String dataId;
|
||||
public boolean isLogEnable() {
|
||||
return logEnable;
|
||||
}
|
||||
|
||||
private String group = Constants.DEFAULT_GROUP;
|
||||
public void setLogEnable(boolean logEnable) {
|
||||
this.logEnable = logEnable;
|
||||
}
|
||||
|
||||
private ConfigType type;
|
||||
public boolean isSnapshotEnable() {
|
||||
return snapshotEnable;
|
||||
}
|
||||
|
||||
private String maxRetry;
|
||||
public void setSnapshotEnable(boolean snapshotEnable) {
|
||||
this.snapshotEnable = snapshotEnable;
|
||||
}
|
||||
|
||||
private String configLongPollTimeout;
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuffer sb = new StringBuffer("Bootstrap{");
|
||||
sb.append("enable=").append(enable);
|
||||
sb.append(", snapshotEnable=").append(snapshotEnable);
|
||||
sb.append(", logEnable=").append(logEnable);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
private String configRetryTime;
|
||||
public static class Config {
|
||||
|
||||
private boolean autoRefresh = false;
|
||||
private String serverAddr;
|
||||
|
||||
private boolean enableRemoteSyncConfig = false;
|
||||
private String endpoint;
|
||||
|
||||
public String getServerAddr() {
|
||||
return serverAddr;
|
||||
}
|
||||
private String namespace;
|
||||
|
||||
public void setServerAddr(String serverAddr) {
|
||||
this.serverAddr = serverAddr;
|
||||
}
|
||||
private String accessKey;
|
||||
|
||||
public String getEndpoint() {
|
||||
return endpoint;
|
||||
}
|
||||
private String secretKey;
|
||||
|
||||
public void setEndpoint(String endpoint) {
|
||||
this.endpoint = endpoint;
|
||||
}
|
||||
private String ramRoleName;
|
||||
|
||||
public String getNamespace() {
|
||||
return namespace;
|
||||
}
|
||||
private String dataId;
|
||||
|
||||
public void setNamespace(String namespace) {
|
||||
this.namespace = namespace;
|
||||
}
|
||||
private String dataIds;
|
||||
|
||||
public String getAccessKey() {
|
||||
return accessKey;
|
||||
}
|
||||
private String group = Constants.DEFAULT_GROUP;
|
||||
|
||||
public void setAccessKey(String accessKey) {
|
||||
this.accessKey = accessKey;
|
||||
}
|
||||
private ConfigType type;
|
||||
|
||||
public String getSecretKey() {
|
||||
return secretKey;
|
||||
}
|
||||
private String maxRetry;
|
||||
|
||||
public void setSecretKey(String secretKey) {
|
||||
this.secretKey = secretKey;
|
||||
}
|
||||
private String configLongPollTimeout;
|
||||
|
||||
public String getDataId() {
|
||||
return dataId;
|
||||
}
|
||||
private String configRetryTime;
|
||||
|
||||
public void setDataId(String dataId) {
|
||||
this.dataId = dataId;
|
||||
}
|
||||
private boolean autoRefresh = false;
|
||||
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
private boolean enableRemoteSyncConfig = false;
|
||||
|
||||
public void setGroup(String group) {
|
||||
this.group = group;
|
||||
}
|
||||
private String username;
|
||||
|
||||
public ConfigType getType() {
|
||||
return type;
|
||||
}
|
||||
private String password;
|
||||
|
||||
public void setType(ConfigType type) {
|
||||
this.type = type;
|
||||
}
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public String getMaxRetry() {
|
||||
return maxRetry;
|
||||
}
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public void setMaxRetry(String maxRetry) {
|
||||
this.maxRetry = maxRetry;
|
||||
}
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public String getConfigLongPollTimeout() {
|
||||
return configLongPollTimeout;
|
||||
}
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public void setConfigLongPollTimeout(String configLongPollTimeout) {
|
||||
this.configLongPollTimeout = configLongPollTimeout;
|
||||
}
|
||||
public String getServerAddr() {
|
||||
return serverAddr;
|
||||
}
|
||||
|
||||
public String getConfigRetryTime() {
|
||||
return configRetryTime;
|
||||
}
|
||||
public void setServerAddr(String serverAddr) {
|
||||
this.serverAddr = serverAddr;
|
||||
}
|
||||
|
||||
public void setConfigRetryTime(String configRetryTime) {
|
||||
this.configRetryTime = configRetryTime;
|
||||
}
|
||||
public String getEndpoint() {
|
||||
return endpoint;
|
||||
}
|
||||
|
||||
public boolean isAutoRefresh() {
|
||||
return autoRefresh;
|
||||
}
|
||||
public void setEndpoint(String endpoint) {
|
||||
this.endpoint = endpoint;
|
||||
}
|
||||
|
||||
public void setAutoRefresh(boolean autoRefresh) {
|
||||
this.autoRefresh = autoRefresh;
|
||||
}
|
||||
public String getNamespace() {
|
||||
return namespace;
|
||||
}
|
||||
|
||||
public boolean isEnableRemoteSyncConfig() {
|
||||
return enableRemoteSyncConfig;
|
||||
}
|
||||
public void setNamespace(String namespace) {
|
||||
this.namespace = namespace;
|
||||
}
|
||||
|
||||
public void setEnableRemoteSyncConfig(boolean enableRemoteSyncConfig) {
|
||||
this.enableRemoteSyncConfig = enableRemoteSyncConfig;
|
||||
}
|
||||
}
|
||||
public String getAccessKey() {
|
||||
return accessKey;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuffer sb = new StringBuffer("Config{");
|
||||
sb.append("serverAddr='").append(serverAddr).append('\'');
|
||||
sb.append(", endpoint='").append(endpoint).append('\'');
|
||||
sb.append(", namespace='").append(namespace).append('\'');
|
||||
sb.append(", accessKey='").append(Objects.isNull(accessKey) ? null : "******").append('\'');
|
||||
sb.append(", secretKey='").append(Objects.isNull(secretKey) ? null : "******").append('\'');
|
||||
sb.append(", ramRoleName='").append(ramRoleName).append('\'');
|
||||
sb.append(", dataId='").append(dataId).append('\'');
|
||||
sb.append(", dataIds='").append(dataIds).append('\'');
|
||||
sb.append(", group='").append(group).append('\'');
|
||||
sb.append(", type=").append(type);
|
||||
sb.append(", maxRetry='").append(maxRetry).append('\'');
|
||||
sb.append(", configLongPollTimeout='").append(configLongPollTimeout)
|
||||
.append('\'');
|
||||
sb.append(", configRetryTime='").append(configRetryTime).append('\'');
|
||||
sb.append(", autoRefresh=").append(autoRefresh);
|
||||
sb.append(", enableRemoteSyncConfig=").append(enableRemoteSyncConfig);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* 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.support;
|
||||
|
||||
import com.alibaba.nacos.spring.core.env.AbstractNacosPropertySourceBuilder;
|
||||
import com.alibaba.nacos.spring.core.env.NacosPropertySource;
|
||||
import com.alibaba.nacos.spring.util.parse.DefaultYamlConfigParse;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.env.EnvironmentPostProcessor;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/**
|
||||
* yaml multi profiles.
|
||||
* <p>
|
||||
* read nacos propertysource:
|
||||
* <p>
|
||||
* 1. {@link AbstractNacosPropertySourceBuilder#doBuild(String, BeanDefinition, Map)}<br/>
|
||||
* 2. {@link NacosPropertySource#NacosPropertySource(String, String, String, String, String)}<br/>
|
||||
* 3. {@link com.alibaba.nacos.spring.util.NacosUtils#toProperties(String, String, String, String)}<br/>
|
||||
* 4. {@link com.alibaba.nacos.spring.util.ConfigParseUtils#toProperties(String, String, String, String)}<br/>
|
||||
*
|
||||
* @author <a href="mailto:yanglu_u@126.com">dbses</a>
|
||||
*/
|
||||
public class MultiProfilesYamlConfigParseSupport extends DefaultYamlConfigParse implements EnvironmentPostProcessor {
|
||||
|
||||
private static final String SPRING_PROFILES = "spring.profiles";
|
||||
|
||||
private static String[] profileArray = {};
|
||||
|
||||
@Override
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
|
||||
String[] profiles = environment.getActiveProfiles();
|
||||
// fall back to default profiles
|
||||
if (profiles.length == 0) {
|
||||
profiles = environment.getDefaultProfiles();
|
||||
}
|
||||
// set once
|
||||
if (profileArray.length == 0) {
|
||||
profileArray = profiles;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> parse(String configText) {
|
||||
final AtomicReference<Map<String, Object>> result = new AtomicReference<>();
|
||||
process(map -> {
|
||||
// first block
|
||||
if (result.get() == null) {
|
||||
result.set(map);
|
||||
} else {
|
||||
setFromOtherBlock(result, map);
|
||||
}
|
||||
}, createYaml(), configText);
|
||||
return result.get();
|
||||
}
|
||||
|
||||
private void setFromOtherBlock(AtomicReference<Map<String, Object>> result, Map<String, Object> map) {
|
||||
if (map.get(SPRING_PROFILES) == null) {
|
||||
result.get().putAll(map);
|
||||
return;
|
||||
}
|
||||
|
||||
for (String profile : profileArray) {
|
||||
if (profile.equals(map.get(SPRING_PROFILES))) {
|
||||
result.get().putAll(map);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* for unit test
|
||||
*/
|
||||
static void setProfileArray(String[] profiles) {
|
||||
profileArray = profiles;
|
||||
}
|
||||
|
||||
}
|
|
@ -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.2.3
|
||||
*/
|
||||
public class AttributeExtractTask implements Callable<Map<String, String>> {
|
||||
|
||||
private final String prefix;
|
||||
private final ConfigurableEnvironment environment;
|
||||
|
||||
public AttributeExtractTask(String prefix, ConfigurableEnvironment environment) {
|
||||
this.prefix = prefix;
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> call() throws Exception {
|
||||
List<Map<String, String>> defer = new LinkedList<>();
|
||||
MutablePropertySources mutablePropertySources = environment.getPropertySources();
|
||||
|
||||
for (PropertySource propertySource : mutablePropertySources) {
|
||||
calculate(propertySource.getSource(), defer);
|
||||
}
|
||||
|
||||
Map<String, String> result = new HashMap<>(32);
|
||||
Collections.reverse(defer);
|
||||
for (Map<String, String> item : defer) {
|
||||
result.putAll(item);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void calculate(Object source, List<Map<String, String>> defer) {
|
||||
if (source instanceof PropertySource) {
|
||||
calculate(((PropertySource) source).getSource(), defer);
|
||||
}
|
||||
if (source instanceof Map) {
|
||||
Map<String, String> 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, String.valueOf(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,233 @@
|
|||
/*
|
||||
* 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.ListIterator;
|
||||
import java.util.Properties;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
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.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.MutablePropertySources;
|
||||
import org.springframework.core.env.StandardEnvironment;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static com.alibaba.nacos.spring.util.NacosUtils.buildDefaultPropertySourceName;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
|
||||
* @author <a href="mailto:guofuyinan@gmail.com">guofuyinan</a>
|
||||
* @since 0.2.3
|
||||
*/
|
||||
public class NacosConfigLoader {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(NacosConfigLoader.class);
|
||||
|
||||
private Properties globalProperties = new Properties();
|
||||
|
||||
private final Function<Properties, ConfigService> builder;
|
||||
private final List<DeferNacosPropertySource> nacosPropertySources = new LinkedList<>();
|
||||
|
||||
public NacosConfigLoader(Function<Properties, ConfigService> builder) {
|
||||
this.builder = builder;
|
||||
}
|
||||
|
||||
public void loadConfig(ConfigurableEnvironment environment, NacosConfigProperties nacosConfigProperties) {
|
||||
globalProperties = buildGlobalNacosProperties(environment, nacosConfigProperties);
|
||||
MutablePropertySources mutablePropertySources = environment.getPropertySources();
|
||||
List<NacosPropertySource> sources = reqGlobalNacosConfig(environment, globalProperties, nacosConfigProperties);
|
||||
for (NacosConfigProperties.Config config : nacosConfigProperties.getExtConfig()) {
|
||||
List<NacosPropertySource> elements = reqSubNacosConfig(environment, config,
|
||||
globalProperties, config.getType());
|
||||
sources.addAll(elements);
|
||||
}
|
||||
if (nacosConfigProperties.isRemoteFirst()) {
|
||||
for (ListIterator<NacosPropertySource> itr = sources.listIterator(sources.size()); itr.hasPrevious();) {
|
||||
mutablePropertySources.addAfter(
|
||||
StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, itr.previous());
|
||||
}
|
||||
} else {
|
||||
for (NacosPropertySource propertySource : sources) {
|
||||
mutablePropertySources.addLast(propertySource);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Properties buildGlobalNacosProperties(ConfigurableEnvironment environment, NacosConfigProperties nacosConfigProperties) {
|
||||
return NacosPropertiesBuilder.buildNacosProperties(environment,
|
||||
nacosConfigProperties.getServerAddr(),
|
||||
nacosConfigProperties.getNamespace(), nacosConfigProperties.getEndpoint(),
|
||||
nacosConfigProperties.getSecretKey(),
|
||||
nacosConfigProperties.getAccessKey(),
|
||||
nacosConfigProperties.getRamRoleName(),
|
||||
nacosConfigProperties.getConfigLongPollTimeout(),
|
||||
nacosConfigProperties.getConfigRetryTime(),
|
||||
nacosConfigProperties.getMaxRetry(),
|
||||
nacosConfigProperties.getContextPath(),
|
||||
nacosConfigProperties.isEnableRemoteSyncConfig(),
|
||||
nacosConfigProperties.getUsername(), nacosConfigProperties.getPassword());
|
||||
}
|
||||
|
||||
private Properties buildSubNacosProperties(ConfigurableEnvironment environment, Properties globalProperties,
|
||||
NacosConfigProperties.Config config) {
|
||||
Properties sub = NacosPropertiesBuilder.buildNacosProperties(environment,
|
||||
config.getServerAddr(), config.getNamespace(), config.getEndpoint(),
|
||||
config.getSecretKey(), config.getAccessKey(), config.getRamRoleName(),
|
||||
config.getConfigLongPollTimeout(), config.getConfigRetryTime(),
|
||||
config.getMaxRetry(),null, config.isEnableRemoteSyncConfig(),
|
||||
config.getUsername(), config.getPassword());
|
||||
NacosPropertiesBuilder.merge(sub, globalProperties);
|
||||
return sub;
|
||||
}
|
||||
|
||||
private List<NacosPropertySource> reqGlobalNacosConfig(ConfigurableEnvironment environment, Properties globalProperties,
|
||||
NacosConfigProperties nacosConfigProperties) {
|
||||
List<String> dataIds = new ArrayList<>();
|
||||
// Loads all data-id information into the list in the list
|
||||
if (!StringUtils.hasLength(nacosConfigProperties.getDataId())) {
|
||||
final String ids = environment
|
||||
.resolvePlaceholders(nacosConfigProperties.getDataIds());
|
||||
if(StringUtils.hasText(ids)){
|
||||
dataIds.addAll(Arrays.stream(ids.split(","))
|
||||
.filter(StringUtils::hasText)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
else {
|
||||
dataIds.add(nacosConfigProperties.getDataId());
|
||||
}
|
||||
final String groupName = environment
|
||||
.resolvePlaceholders(nacosConfigProperties.getGroup());
|
||||
final boolean isAutoRefresh = nacosConfigProperties.isAutoRefresh();
|
||||
return new ArrayList<>(Arrays.asList(reqNacosConfig(environment, globalProperties,
|
||||
dataIds.toArray(new String[0]), groupName, nacosConfigProperties.getType(), isAutoRefresh)));
|
||||
}
|
||||
|
||||
private List<NacosPropertySource> reqSubNacosConfig(ConfigurableEnvironment environment,
|
||||
NacosConfigProperties.Config config, Properties globalProperties,
|
||||
ConfigType type) {
|
||||
Properties subConfigProperties = buildSubNacosProperties(environment, globalProperties,
|
||||
config);
|
||||
ArrayList<String> dataIds = new ArrayList<>();
|
||||
if (!StringUtils.hasLength(config.getDataId())) {
|
||||
final String ids = environment.resolvePlaceholders(config.getDataIds());
|
||||
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(environment, subConfigProperties,
|
||||
dataIds.toArray(new String[0]), groupName, type, isAutoRefresh)));
|
||||
}
|
||||
|
||||
private NacosPropertySource[] reqNacosConfig(ConfigurableEnvironment environment, 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.hasLength(dataIds[i])) {
|
||||
continue;
|
||||
}
|
||||
// Remove excess Spaces
|
||||
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 : {}",
|
||||
nacosPropertySource.getDataId(), nacosPropertySource.getGroupId());
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
public Properties getGlobalProperties() {
|
||||
return globalProperties;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* 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 com.alibaba.boot.nacos.config.properties.NacosConfigProperties;
|
||||
import com.alibaba.nacos.api.config.ConfigService;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
|
||||
import java.util.Properties;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* NacosConfigLoaderFactory.
|
||||
* @author hujun
|
||||
*/
|
||||
public class NacosConfigLoaderFactory {
|
||||
|
||||
private static volatile NacosConfigLoader nacosConfigLoader;
|
||||
|
||||
public static NacosConfigLoader getSingleton(Function<Properties, ConfigService> builder) {
|
||||
if (nacosConfigLoader == null) {
|
||||
synchronized (NacosConfigLoaderFactory.class) {
|
||||
if (nacosConfigLoader == null) {
|
||||
nacosConfigLoader = new NacosConfigLoader(builder);
|
||||
}
|
||||
}
|
||||
}
|
||||
return nacosConfigLoader;
|
||||
}
|
||||
}
|
|
@ -18,87 +18,38 @@ package com.alibaba.boot.nacos.config.util;
|
|||
|
||||
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 com.alibaba.nacos.api.config.ConfigService;
|
||||
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.boot.context.properties.bind.Bindable;
|
||||
import org.springframework.boot.context.properties.bind.Binder;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
|
||||
import java.util.Properties;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Springboot used to own property binding configured binding
|
||||
*
|
||||
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
|
||||
* @since
|
||||
* @since 0.2.3
|
||||
*/
|
||||
public class NacosConfigPropertiesUtils {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(NacosConfigPropertiesUtils.class);
|
||||
private static final Logger logger = LoggerFactory
|
||||
.getLogger(NacosConfigPropertiesUtils.class);
|
||||
|
||||
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 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 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;
|
||||
}
|
||||
|
||||
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 nacosConfigProperties = new NacosConfigProperties();
|
||||
Binder binder = Binder.get(environment);
|
||||
ResolvableType type = ResolvableType.forClass(NacosConfigProperties.class);
|
||||
Bindable<?> target = Bindable.of(type).withExistingValue(nacosConfigProperties);
|
||||
binder.bind(NacosConfigConstants.PREFIX, target);
|
||||
logger.info("nacosConfigProperties : {}", nacosConfigProperties);
|
||||
return nacosConfigProperties;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,65 +16,65 @@
|
|||
*/
|
||||
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.core.env.Environment;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
|
||||
* @since
|
||||
* @since 0.2.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(Environment environment,
|
||||
String serverAddr, String namespaceId, String endpoint, String secretKey,
|
||||
String accessKey, String ramRoleName, String configLongPollTimeout,
|
||||
String configRetryTimeout, String maxRetry,String contextPath, boolean enableRemoteSyncConfig,
|
||||
String username, String password) {
|
||||
Properties properties = new Properties();
|
||||
processPropertiesData(properties,environment,serverAddr,PropertyKeyConst.SERVER_ADDR);
|
||||
processPropertiesData(properties,environment,namespaceId,PropertyKeyConst.NAMESPACE);
|
||||
processPropertiesData(properties,environment,endpoint,PropertyKeyConst.ENDPOINT);
|
||||
processPropertiesData(properties,environment,secretKey,PropertyKeyConst.SECRET_KEY);
|
||||
processPropertiesData(properties,environment,accessKey,PropertyKeyConst.ACCESS_KEY);
|
||||
processPropertiesData(properties,environment,ramRoleName,PropertyKeyConst.RAM_ROLE_NAME);
|
||||
processPropertiesData(properties,environment,configLongPollTimeout,PropertyKeyConst.CONFIG_LONG_POLL_TIMEOUT);
|
||||
processPropertiesData(properties,environment,configRetryTimeout,PropertyKeyConst.CONFIG_RETRY_TIME);
|
||||
processPropertiesData(properties,environment,contextPath,PropertyKeyConst.CONTEXT_PATH);
|
||||
processPropertiesData(properties,environment,maxRetry,PropertyKeyConst.MAX_RETRY);
|
||||
processPropertiesData(properties,environment,username,PropertyKeyConst.USERNAME);
|
||||
processPropertiesData(properties,environment,password,PropertyKeyConst.PASSWORD);
|
||||
|
||||
properties.put(PropertyKeyConst.ENABLE_REMOTE_SYNC_CONFIG,
|
||||
String.valueOf(enableRemoteSyncConfig));
|
||||
return properties;
|
||||
}
|
||||
|
||||
private static void processPropertiesData(Properties properties,Environment environment,String keyword,String key) {
|
||||
if (StringUtils.isNotBlank(keyword)) {
|
||||
properties.put(key ,environment.resolvePlaceholders(keyword));
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,26 +20,27 @@ import java.beans.PropertyEditorSupport;
|
|||
|
||||
/**
|
||||
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
|
||||
* @since
|
||||
* @since 0.2.3
|
||||
*/
|
||||
public class NacosCharSequenceEditor extends PropertyEditorSupport {
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsText() {
|
||||
Object value = getValue();
|
||||
return String.valueOf(value);
|
||||
}
|
||||
@Override
|
||||
public String getAsText() {
|
||||
Object value = getValue();
|
||||
return String.valueOf(value);
|
||||
}
|
||||
}
|
|
@ -16,93 +16,92 @@
|
|||
*/
|
||||
package com.alibaba.boot.nacos.config.util.editor;
|
||||
|
||||
import java.beans.PropertyEditorSupport;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.beans.PropertyEditorSupport;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
|
||||
* @since
|
||||
* @since 0.2.3
|
||||
*/
|
||||
public class NacosCustomBooleanEditor extends PropertyEditorSupport {
|
||||
|
||||
public static final String VALUE_TRUE = "true";
|
||||
public static final String VALUE_FALSE = "false";
|
||||
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_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_YES = "yes";
|
||||
public static final String VALUE_NO = "no";
|
||||
|
||||
public static final String VALUE_1 = "1";
|
||||
public static final String VALUE_0 = "0";
|
||||
public static final String VALUE_1 = "1";
|
||||
public static final String VALUE_0 = "0";
|
||||
|
||||
@Nullable
|
||||
private final String trueString;
|
||||
|
||||
@Nullable
|
||||
private final String trueString;
|
||||
@Nullable
|
||||
private final String falseString;
|
||||
|
||||
@Nullable
|
||||
private final String falseString;
|
||||
private final boolean allowEmpty;
|
||||
|
||||
private final boolean allowEmpty;
|
||||
public NacosCustomBooleanEditor(boolean allowEmpty) {
|
||||
this(null, null, 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;
|
||||
}
|
||||
|
||||
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)));
|
||||
}
|
||||
|
||||
@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 + "]");
|
||||
}
|
||||
}
|
||||
|
||||
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 "";
|
||||
}
|
||||
}
|
||||
@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 "";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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,132 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
|
||||
* @since
|
||||
* @since 0.2.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<>(8);
|
||||
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 removePropertyChangeListener(PropertyChangeListener var1) {
|
||||
synchronized(this.listeners) {
|
||||
this.listeners.remove(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,149 @@
|
|||
/*
|
||||
* 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.log;
|
||||
|
||||
import com.alibaba.boot.nacos.config.properties.NacosConfigProperties;
|
||||
import com.alibaba.boot.nacos.config.util.NacosConfigLoader;
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.config.ConfigService;
|
||||
import com.alibaba.nacos.api.config.listener.AbstractListener;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.client.config.utils.ConcurrentDiskUtil;
|
||||
import com.alibaba.nacos.client.config.utils.JvmUtil;
|
||||
import com.alibaba.nacos.client.logging.NacosLogging;
|
||||
import com.alibaba.nacos.client.utils.LogUtils;
|
||||
import com.alibaba.nacos.common.utils.IoUtils;
|
||||
import com.alibaba.nacos.common.utils.StringUtils;
|
||||
import com.alibaba.nacos.spring.util.NacosUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.boot.context.logging.LoggingApplicationListener;
|
||||
import org.springframework.boot.logging.LoggingInitializationContext;
|
||||
import org.springframework.boot.logging.LoggingSystem;
|
||||
import org.springframework.boot.logging.LoggingSystemFactory;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Start:
|
||||
* Step1: get the log XML configuration from the configuration center
|
||||
* Step2: modify the springboot log configuration path
|
||||
* Modifying log configuration during operation:
|
||||
* Clean up the configuration through LoggingSystem and reload the configuration.
|
||||
*
|
||||
* @author <a href="mailto:hujun3@xiaomi.com">hujun</a>
|
||||
*/
|
||||
public class LogAutoFreshProcess {
|
||||
|
||||
private static final Logger LOGGER = LogUtils.logger(LogAutoFreshProcess.class);
|
||||
|
||||
private final NacosConfigProperties nacosConfigProperties;
|
||||
|
||||
private final ConfigurableEnvironment environment;
|
||||
|
||||
private final NacosConfigLoader nacosConfigLoader;
|
||||
|
||||
private final Function<Properties, ConfigService> builder;
|
||||
|
||||
private static final List<String> LOG_DATA_ID = new ArrayList<>();
|
||||
|
||||
private static final String LOG_CACHE_BASE = System.getProperty("JM.SNAPSHOT.PATH", System.getProperty("user.home")) + File.separator + "nacos"
|
||||
+ File.separator + "logConfig";
|
||||
|
||||
static {
|
||||
LOG_DATA_ID.add("logback.xml");
|
||||
LOG_DATA_ID.add("log4j2.xml");
|
||||
}
|
||||
|
||||
public static LogAutoFreshProcess build(ConfigurableEnvironment environment, NacosConfigProperties nacosConfigProperties, NacosConfigLoader nacosConfigLoader, Function<Properties, ConfigService> builder) {
|
||||
return new LogAutoFreshProcess(environment, nacosConfigProperties, nacosConfigLoader, builder);
|
||||
}
|
||||
|
||||
private LogAutoFreshProcess(ConfigurableEnvironment environment, NacosConfigProperties nacosConfigProperties, NacosConfigLoader nacosConfigLoader, Function<Properties, ConfigService> builder) {
|
||||
this.nacosConfigProperties = nacosConfigProperties;
|
||||
this.environment = environment;
|
||||
this.nacosConfigLoader = nacosConfigLoader;
|
||||
this.builder = builder;
|
||||
}
|
||||
|
||||
public void process() {
|
||||
final String groupName = environment
|
||||
.resolvePlaceholders(nacosConfigProperties.getGroup());
|
||||
ConfigService configService = builder.apply(nacosConfigLoader.getGlobalProperties());
|
||||
for (String dataId : LOG_DATA_ID) {
|
||||
String content = NacosUtils.getContent(configService, dataId, groupName);
|
||||
if (StringUtils.isNotBlank(content)) {
|
||||
writeLogFile(content, dataId);
|
||||
System.setProperty(LoggingApplicationListener.CONFIG_PROPERTY, LOG_CACHE_BASE + File.separator + dataId);
|
||||
registerListener(configService, dataId, groupName);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void registerListener(ConfigService configService, String dataId, String groupName) {
|
||||
try {
|
||||
configService.addListener(dataId, groupName, new AbstractListener() {
|
||||
@Override
|
||||
public void receiveConfigInfo(String configInfo) {
|
||||
if (StringUtils.isNotBlank(configInfo)) {
|
||||
writeLogFile(configInfo, dataId);
|
||||
reloadConfig(LOG_CACHE_BASE + File.separator + dataId);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (NacosException e) {
|
||||
throw new RuntimeException("ConfigService can't add Listener with dataId : " + dataId, e);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeLogFile(String content, String dataId) {
|
||||
File file = new File(LOG_CACHE_BASE, dataId);
|
||||
File parentFile = file.getParentFile();
|
||||
if (!parentFile.exists()) {
|
||||
boolean isMdOk = parentFile.mkdirs();
|
||||
if (!isMdOk) {
|
||||
LOGGER.error("save log cache error");
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (JvmUtil.isMultiInstance()) {
|
||||
ConcurrentDiskUtil.writeFileContent(file, content, Constants.ENCODE);
|
||||
} else {
|
||||
IoUtils.writeStringToFile(file, content, Constants.ENCODE);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("write log file fail");
|
||||
}
|
||||
}
|
||||
|
||||
private void reloadConfig(String logPath) {
|
||||
LoggingSystem loggingSystem = LoggingSystemFactory.fromSpringFactories()
|
||||
.getLoggingSystem(this.getClass().getClassLoader());
|
||||
loggingSystem.cleanUp();
|
||||
loggingSystem.initialize(new LoggingInitializationContext(environment),
|
||||
logPath, null);
|
||||
NacosLogging.getInstance().loadConfiguration();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"resources": {
|
||||
"includes": [
|
||||
{
|
||||
"pattern": "\\QMETA-INF/services/com.alibaba.nacos.spring.util.ConfigParse\\E"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
com.alibaba.boot.nacos.config.support.MultiProfilesYamlConfigParseSupport
|
|
@ -1,110 +0,0 @@
|
|||
{
|
||||
"hints": [ ],
|
||||
"groups": [ ],
|
||||
"properties": [
|
||||
{
|
||||
"sourceType": "com.alibaba.boot.nacos.config.properties.NacosConfigProperties",
|
||||
"name": "nacos.config.enabled",
|
||||
"description": "enable or disable nacos config feature",
|
||||
"type": "java.lang.Boolean"
|
||||
},
|
||||
{
|
||||
"sourceType": "com.alibaba.boot.nacos.config.properties.NacosConfigProperties",
|
||||
"name": "nacos.config.server-addr",
|
||||
"description": "the server address of nacos",
|
||||
"type": "java.lang.String"
|
||||
},
|
||||
{
|
||||
"sourceType": "com.alibaba.boot.nacos.config.properties.NacosConfigProperties",
|
||||
"name": "nacos.config.context-path",
|
||||
"description": "the context path of nacos server",
|
||||
"type": "java.lang.String"
|
||||
},
|
||||
{
|
||||
"sourceType": "com.alibaba.boot.nacos.config.properties.NacosConfigProperties",
|
||||
"name": "nacos.config.encode",
|
||||
"description": "encode of reading nacos properties",
|
||||
"type": "java.lang.String"
|
||||
},
|
||||
{
|
||||
"sourceType": "com.alibaba.boot.nacos.config.properties.NacosConfigProperties",
|
||||
"name": "nacos.config.endpoint",
|
||||
"description": "the entry domain name of a service in each region",
|
||||
"type": "java.lang.String"
|
||||
},
|
||||
{
|
||||
"sourceType": "com.alibaba.boot.nacos.config.properties.NacosConfigProperties",
|
||||
"name": "nacos.config.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.config.properties.NacosConfigProperties",
|
||||
"name": "nacos.config.access-key",
|
||||
"description": "the accesskey of Alibaba Cloud Account",
|
||||
"type": "java.lang.String"
|
||||
},
|
||||
{
|
||||
"sourceType": "com.alibaba.boot.nacos.config.properties.NacosConfigProperties",
|
||||
"name": "nacos.config.secret-key",
|
||||
"description": "the secretkey 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.group",
|
||||
"type": "java.lang.String"
|
||||
},
|
||||
{
|
||||
"sourceType": "com.alibaba.boot.nacos.config.properties.NacosConfigProperties",
|
||||
"name": "nacos.config.auto-refresh",
|
||||
"type": "java.lang.Boolean"
|
||||
},
|
||||
{
|
||||
"sourceType": "com.alibaba.boot.nacos.config.properties.NacosConfigProperties",
|
||||
"name": "nacos.config.max-retry",
|
||||
"description": "the secretkey of Alibaba Cloud Account",
|
||||
"type": "java.lang.String"
|
||||
},
|
||||
{
|
||||
"sourceType": "com.alibaba.boot.nacos.config.properties.NacosConfigProperties",
|
||||
"name": "nacos.config.config-long-poll-timeout",
|
||||
"description": "the secretkey of Alibaba Cloud Account",
|
||||
"type": "java.lang.String"
|
||||
},
|
||||
{
|
||||
"sourceType": "com.alibaba.boot.nacos.config.properties.NacosConfigProperties",
|
||||
"name": "nacos.config.config-retry-time",
|
||||
"description": "the secretkey of Alibaba Cloud Account",
|
||||
"type": "java.lang.String"
|
||||
},
|
||||
{
|
||||
"sourceType": "com.alibaba.boot.nacos.config.properties.NacosConfigProperties",
|
||||
"name": "nacos.config.type",
|
||||
"description": "the secretkey of Alibaba Cloud Account",
|
||||
"type": "com.alibaba.nacos.api.config.ConfigType"
|
||||
},{
|
||||
"sourceType": "com.alibaba.boot.nacos.config.properties.NacosConfigProperties",
|
||||
"name": "nacos.config.enable-remote-sync-config",
|
||||
"description": "the secretkey of Alibaba Cloud Account",
|
||||
"type": "java.lang.Boolean"
|
||||
},
|
||||
{
|
||||
"sourceType": "com.alibaba.boot.nacos.config.properties.NacosConfigProperties",
|
||||
"name": "nacos.config.bootstrap.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",
|
||||
"description": "the secretkey of Alibaba Cloud Account",
|
||||
"type": "java.util.List<com.alibaba.boot.nacos.config.properties.NacosConfigProperties.Config>"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,4 +1,9 @@
|
|||
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.context.ApplicationContextInitializer=\
|
||||
# com.alibaba.boot.nacos.config.autoconfigure.NacosConfigApplicationContextInitializer
|
||||
org.springframework.boot.env.EnvironmentPostProcessor=\
|
||||
com.alibaba.boot.nacos.config.autoconfigure.NacosConfigEnvironmentProcessor,\
|
||||
com.alibaba.boot.nacos.config.support.MultiProfilesYamlConfigParseSupport
|
||||
org.springframework.context.ApplicationListener=\
|
||||
com.alibaba.boot.nacos.config.logging.NacosLoggingListener
|
|
@ -0,0 +1,4 @@
|
|||
com.alibaba.boot.nacos.config.autoconfigure.NacosConfigAutoConfiguration
|
||||
com.alibaba.boot.nacos.config.autoconfigure.NacosConfigEnvironmentProcessor
|
||||
com.alibaba.boot.nacos.config.support.MultiProfilesYamlConfigParseSupport
|
||||
com.alibaba.boot.nacos.config.logging.NacosLoggingListener
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* 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.autoconfigure;
|
||||
|
||||
import com.alibaba.boot.nacos.config.autoconfigure.NacosBootConfigException;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* {@link NacosBootConfigException} Test
|
||||
* @ClassName: NacosBootConfigExceptionTest
|
||||
* @Author: ChenHao26
|
||||
* @Date: 2022/8/12 15:56
|
||||
*/
|
||||
public class NacosBootConfigExceptionTest {
|
||||
|
||||
@Test
|
||||
public void getCons() {
|
||||
try {
|
||||
testMethod("spring boot");
|
||||
}catch (Exception e) {
|
||||
Assert.assertTrue(e instanceof NacosBootConfigException);
|
||||
}
|
||||
}
|
||||
|
||||
private void testMethod(String str) {
|
||||
if (str.startsWith("spring")) {
|
||||
throw new NacosBootConfigException(new Throwable());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* 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.autoconfigure;
|
||||
|
||||
import com.alibaba.boot.nacos.config.autoconfigure.NacosConfigApplicationContextInitializer;
|
||||
import com.alibaba.boot.nacos.config.autoconfigure.NacosConfigAutoConfiguration;
|
||||
import com.alibaba.boot.nacos.config.autoconfigure.NacosConfigBootBeanDefinitionRegistrar;
|
||||
import com.alibaba.boot.nacos.config.autoconfigure.NacosConfigEnvironmentProcessor;
|
||||
import com.alibaba.boot.nacos.config.properties.NacosConfigProperties;
|
||||
import com.alibaba.boot.nacos.config.util.NacosConfigLoader;
|
||||
import com.alibaba.boot.nacos.config.util.NacosConfigLoaderFactory;
|
||||
import com.alibaba.boot.nacos.config.util.NacosConfigPropertiesUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
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.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* {@link NacosConfigApplicationContextInitializer} Test
|
||||
* @ClassName: NacosConfigApplicationContextInitializerTest
|
||||
* @Author: ChenHao26
|
||||
* @Date: 2022/8/12 15:25
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@TestPropertySource(properties = { "nacos.config.server-addr=localhost" })
|
||||
@SpringBootTest(classes = { NacosConfigAutoConfiguration.class })
|
||||
public class NacosConfigApplicationContextInitializerTest {
|
||||
|
||||
private NacosConfigApplicationContextInitializer nacosConfigApplicationContextInitializer;
|
||||
|
||||
@Autowired
|
||||
private ConfigurableEnvironment environment;
|
||||
|
||||
@Autowired
|
||||
private NacosConfigProperties nacosConfigProperties;
|
||||
|
||||
@Autowired
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@Before
|
||||
public void testNacosConfigApplicationContextInitializer() {
|
||||
nacosConfigApplicationContextInitializer = new NacosConfigApplicationContextInitializer(new NacosConfigEnvironmentProcessor());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initialize(){
|
||||
try {
|
||||
nacosConfigProperties = NacosConfigPropertiesUtils
|
||||
.buildNacosConfigProperties(environment);
|
||||
Assert.assertNotNull(nacosConfigProperties);
|
||||
NacosConfigLoader singleton = NacosConfigLoaderFactory.getSingleton(null);
|
||||
Assert.assertNotNull(singleton);
|
||||
nacosConfigApplicationContextInitializer.initialize(context);
|
||||
} catch (Exception e) {
|
||||
Assert.assertNotNull(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,7 +16,10 @@
|
|||
*/
|
||||
package com.alibaba.boot.nacos.autoconfigure;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import com.alibaba.boot.nacos.config.autoconfigure.NacosConfigAutoConfiguration;
|
||||
import com.alibaba.boot.nacos.config.binder.NacosBootConfigurationPropertiesBinder;
|
||||
import com.alibaba.boot.nacos.config.properties.NacosConfigProperties;
|
||||
import com.alibaba.nacos.api.PropertyKeyConst;
|
||||
import com.alibaba.nacos.api.annotation.NacosInjected;
|
||||
|
@ -25,6 +28,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 +36,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 +43,50 @@ 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
|
||||
public void testNacosConfigGlobalBean() {
|
||||
Assert.assertNotNull(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));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNacosConfigBootBeanDefinitionRegistrar() {
|
||||
Assert.assertNotNull(applicationContext.getBean(NacosBootConfigurationPropertiesBinder.BEAN_NAME));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* 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.autoconfigure;
|
||||
|
||||
import com.alibaba.boot.nacos.config.autoconfigure.NacosConfigAutoConfiguration;
|
||||
import com.alibaba.boot.nacos.config.autoconfigure.NacosConfigBootBeanDefinitionRegistrar;
|
||||
import com.alibaba.boot.nacos.config.binder.NacosBootConfigurationPropertiesBinder;
|
||||
import com.alibaba.nacos.client.utils.LogUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* {@link NacosConfigBootBeanDefinitionRegistrar} Test
|
||||
* @ClassName: NacosConfigBootBeanDefinitionRegistrarTest
|
||||
* @Author: ChenHao26
|
||||
* @Date: 2022/8/12 15:38
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@TestPropertySource(properties = { "nacos.config.server-addr=localhost" })
|
||||
@SpringBootTest(classes = { NacosConfigAutoConfiguration.class })
|
||||
public class NacosConfigBootBeanDefinitionRegistrarTest {
|
||||
|
||||
private static final Logger LOGGER = LogUtils.logger(NacosConfigBootBeanDefinitionRegistrarTest.class);
|
||||
|
||||
private NacosConfigBootBeanDefinitionRegistrar nacosConfigBootBeanDefinitionRegistrar;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
nacosConfigBootBeanDefinitionRegistrar = new NacosConfigBootBeanDefinitionRegistrar();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setBeanFactory(){
|
||||
try {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition("beanName");
|
||||
Assert.assertNotNull(builder);
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
nacosConfigBootBeanDefinitionRegistrar.setBeanFactory(beanFactory);
|
||||
Assert.assertNotNull(beanFactory.getBeanDefinition(NacosBootConfigurationPropertiesBinder.BEAN_NAME));
|
||||
nacosConfigBootBeanDefinitionRegistrar.setBeanFactory(beanFactory);
|
||||
}catch (Exception e) {
|
||||
LOGGER.error("error info: {}",e.toString());
|
||||
Assert.assertNull(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.boot.nacos.autoconfigure;
|
||||
|
||||
import com.alibaba.boot.nacos.config.autoconfigure.NacosConfigAutoConfiguration;
|
||||
import com.alibaba.boot.nacos.config.autoconfigure.NacosConfigEnvironmentProcessor;
|
||||
import com.alibaba.boot.nacos.config.binder.NacosBootConfigurationPropertiesBinder;
|
||||
import com.alibaba.boot.nacos.config.properties.NacosConfigProperties;
|
||||
import com.alibaba.boot.nacos.config.util.NacosConfigPropertiesUtils;
|
||||
import com.alibaba.nacos.client.config.NacosConfigService;
|
||||
import com.alibaba.nacos.client.utils.LogUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* {@link NacosBootConfigurationPropertiesBinder} Test
|
||||
* @ClassName: NacosConfigEnvironmentProcessorTest
|
||||
* @Author: ChenHao26
|
||||
* @Date: 2022/8/12 15:43
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@TestPropertySource(properties = { "nacos.config.server-addr=localhost" })
|
||||
@SpringBootTest(classes = { NacosConfigAutoConfiguration.class })
|
||||
public class NacosConfigEnvironmentProcessorTest {
|
||||
|
||||
private NacosConfigEnvironmentProcessor nacosConfigEnvironmentProcessor;
|
||||
|
||||
@Autowired
|
||||
private ConfigurableEnvironment environment;
|
||||
|
||||
private static final Logger LOGGER = LogUtils.logger(NacosConfigEnvironmentProcessorTest.class);
|
||||
|
||||
@Mock
|
||||
private NacosConfigProperties nacosConfigProperties;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
nacosConfigEnvironmentProcessor = new NacosConfigEnvironmentProcessor();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postProcessEnvironment() {
|
||||
try {
|
||||
NacosConfigProperties nacosConfigProperties1 = NacosConfigPropertiesUtils.buildNacosConfigProperties(
|
||||
environment);
|
||||
Assert.assertFalse(nacosConfigProperties1.isEnableRemoteSyncConfig());
|
||||
nacosConfigEnvironmentProcessor.postProcessEnvironment(environment, new SpringApplication());
|
||||
}catch (Exception e) {
|
||||
LOGGER.error("error info :{} ",e);
|
||||
Assert.assertNull(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getOrder() {
|
||||
int order = nacosConfigEnvironmentProcessor.getOrder();
|
||||
Assert.assertNotNull(order);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
* 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.binder;
|
||||
|
||||
import com.alibaba.boot.nacos.config.autoconfigure.NacosConfigAutoConfiguration;
|
||||
import com.alibaba.boot.nacos.config.binder.NacosBootConfigurationPropertiesBinder;
|
||||
import com.alibaba.nacos.api.config.ConfigService;
|
||||
import com.alibaba.nacos.api.config.annotation.NacosConfigurationProperties;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.spring.context.event.config.EventPublishingConfigService;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
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.context.ConfigurableApplicationContext;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* {@link NacosBootConfigurationPropertiesBinder} Test
|
||||
* @ClassName: NacosBootConfigurationPropertiesBinderTest
|
||||
* @Author: ChenHao26
|
||||
* @Date: 2022/8/12 16:00
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@TestPropertySource(properties = { "nacos.config.server-addr=localhost" })
|
||||
@SpringBootTest(classes = { NacosConfigAutoConfiguration.class })
|
||||
public class NacosBootConfigurationPropertiesBinderTest {
|
||||
|
||||
private Binder binder;
|
||||
|
||||
@Autowired
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
binder = new Binder(context);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findFactoryMethod(){
|
||||
Method beanName = binder.findFactoryMethod(NacosBootConfigurationPropertiesBinder.BEAN_NAME);
|
||||
Assert.assertNull(beanName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoBind() {
|
||||
People people = new People();
|
||||
binder.doBind(people, "people", "people", "people", "properties",
|
||||
People.class.getAnnotation(NacosConfigurationProperties.class), "people.name=SuperZ1999\npeople.age=24",
|
||||
new EventPublishingConfigService(null, null, context, null));
|
||||
Assert.assertEquals(people.getName(), "SuperZ1999");
|
||||
Assert.assertEquals(people.getAge(), 24);
|
||||
}
|
||||
|
||||
static class Binder extends NacosBootConfigurationPropertiesBinder {
|
||||
|
||||
public Binder(ConfigurableApplicationContext applicationContext) {
|
||||
super(applicationContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doBind(Object bean, String beanName, String dataId, String groupId, String configType, NacosConfigurationProperties properties, String content, ConfigService configService) {
|
||||
super.doBind(bean, beanName, dataId, groupId, configType, properties, content, configService);
|
||||
}
|
||||
}
|
||||
|
||||
@NacosConfigurationProperties(prefix = "people", dataId = "people", groupId = "people")
|
||||
static class People {
|
||||
private String name;
|
||||
private int age;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,162 @@
|
|||
/*
|
||||
* 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.support;
|
||||
|
||||
import com.alibaba.boot.nacos.config.autoconfigure.NacosConfigAutoConfiguration;
|
||||
import com.alibaba.nacos.spring.util.ConfigParseUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
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.core.env.Environment;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* {@link MultiProfilesYamlConfigParseSupport} Test
|
||||
*
|
||||
* @author <a href="mailto:yanglu_u@126.com">dbses</a>
|
||||
*/
|
||||
public class MultiProfilesYamlConfigParseSupportTest {
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ActiveProfiles({"alpha"})
|
||||
@SpringBootTest(classes = {NacosConfigAutoConfiguration.class})
|
||||
public static class OneProfiles {
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
// because MultiProfilesYamlConfigParseSupport # postProcessEnvironment() run once,
|
||||
// so it should set profilesArray before test
|
||||
MultiProfilesYamlConfigParseSupport.setProfileArray(environment.getActiveProfiles());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oneProfiles_normal() {
|
||||
String content = "test1:\n" +
|
||||
" config: 2\n" +
|
||||
"\n" +
|
||||
"---\n" +
|
||||
"spring:\n" +
|
||||
" profiles: alpha\n" +
|
||||
"test1:\n" +
|
||||
" config: alpha\n" +
|
||||
"\n" +
|
||||
"---\n" +
|
||||
"spring:\n" +
|
||||
" profiles: beta\n" +
|
||||
"test1:\n" +
|
||||
" config: beta";
|
||||
Assert.assertEquals(environment.getActiveProfiles()[0], "alpha");
|
||||
Object result = ConfigParseUtils.toProperties("test.yaml", "test", content, "yaml")
|
||||
.get("test1.config");
|
||||
Assert.assertEquals("alpha", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oneProfiles_when_content_profiles_isnull() {
|
||||
String content = "test1:\n" +
|
||||
" config: 2\n" +
|
||||
"\n" +
|
||||
"---\n" +
|
||||
"test1:\n" +
|
||||
" config: alpha\n" +
|
||||
"\n" +
|
||||
"---\n" +
|
||||
"test1:\n" +
|
||||
" config: beta";
|
||||
Object result = ConfigParseUtils.toProperties("test.yaml", "test", content, "yaml")
|
||||
.get("test1.config");
|
||||
Assert.assertEquals("beta", result);
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ActiveProfiles({"alpha", "beta"})
|
||||
@SpringBootTest(classes = {NacosConfigAutoConfiguration.class})
|
||||
public static class TwoProfiles {
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MultiProfilesYamlConfigParseSupport.setProfileArray(environment.getActiveProfiles());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void twoProfiles_normal() {
|
||||
String content = "test1:\n" +
|
||||
" config: 2\n" +
|
||||
"\n" +
|
||||
"---\n" +
|
||||
"spring:\n" +
|
||||
" profiles: alpha\n" +
|
||||
"test1:\n" +
|
||||
" config: alpha\n" +
|
||||
"\n" +
|
||||
"---\n" +
|
||||
"spring:\n" +
|
||||
" profiles: beta\n" +
|
||||
"test1:\n" +
|
||||
" config: beta";
|
||||
Assert.assertEquals(environment.getActiveProfiles()[0], "alpha");
|
||||
Assert.assertEquals(environment.getActiveProfiles()[1], "beta");
|
||||
Object result = ConfigParseUtils.toProperties("test.yaml", "test", content, "yaml")
|
||||
.get("test1.config");
|
||||
Assert.assertEquals("beta", result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = {NacosConfigAutoConfiguration.class})
|
||||
public static class NoProfiles {
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
@Test
|
||||
public void noProfiles_normal() {
|
||||
String content = "test1:\n" +
|
||||
" config: 2\n" +
|
||||
"\n" +
|
||||
"---\n" +
|
||||
"spring:\n" +
|
||||
" profiles: default\n" +
|
||||
"test1:\n" +
|
||||
" config: default\n" +
|
||||
"\n" +
|
||||
"---\n" +
|
||||
"spring:\n" +
|
||||
" profiles: beta\n" +
|
||||
"test1:\n" +
|
||||
" config: beta";
|
||||
Assert.assertEquals(environment.getActiveProfiles().length, 0);
|
||||
Object result = ConfigParseUtils.toProperties("test.yaml", "test", content, "yaml")
|
||||
.get("test1.config");
|
||||
Assert.assertEquals("default", result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* 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.logging;
|
||||
|
||||
import com.alibaba.boot.nacos.config.logging.NacosLoggingListener;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.ResolvableType;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* {@link NacosLoggingListener} Test
|
||||
* @ClassName: AttributeExtractTaskTest
|
||||
* @Author: ChenHao26
|
||||
* @Date: 2022/8/12 15:08
|
||||
*/
|
||||
public class NacosLoggingListenerTest {
|
||||
private NacosLoggingListener nacosLoggingListener;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
nacosLoggingListener = new NacosLoggingListener();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsEventType() {
|
||||
boolean result = nacosLoggingListener.supportsEventType(ResolvableType.forType(new Type() {
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
return Type.super.getTypeName();
|
||||
}
|
||||
}));
|
||||
Assert.assertEquals(result, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getOrder() {
|
||||
int order = nacosLoggingListener.getOrder();
|
||||
Assert.assertNotNull(order);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* 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.util;
|
||||
|
||||
import com.alibaba.boot.nacos.config.autoconfigure.NacosConfigAutoConfiguration;
|
||||
import com.alibaba.boot.nacos.config.util.AttributeExtractTask;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.MutablePropertySources;
|
||||
import org.springframework.core.env.PropertySources;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* {@link AttributeExtractTask} Test
|
||||
* @ClassName: AttributeExtractTaskTest
|
||||
* @Author: ChenHao26
|
||||
* @Date: 2022/8/12 15:08
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@TestPropertySource(properties = { "nacos.config.server-addr=localhost" })
|
||||
@SpringBootTest(classes = { NacosConfigAutoConfiguration.class })
|
||||
public class AttributeExtractTaskTest {
|
||||
|
||||
private AttributeExtractTask attributeExtractTask;
|
||||
|
||||
@Autowired
|
||||
private ConfigurableEnvironment environment ;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
environment.setDefaultProfiles("prefix01");
|
||||
attributeExtractTask = new AttributeExtractTask("nacos.config",environment);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void call() throws Exception{
|
||||
Map<String, String> map = attributeExtractTask.call();
|
||||
Assert.assertEquals(map.get("nacos.config.server-addr"), "localhost");
|
||||
}
|
||||
}
|
|
@ -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.util;
|
||||
|
||||
import com.alibaba.boot.nacos.config.autoconfigure.NacosConfigAutoConfiguration;
|
||||
import com.alibaba.boot.nacos.config.properties.NacosConfigProperties;
|
||||
import com.alibaba.boot.nacos.config.util.NacosConfigLoader;
|
||||
import com.alibaba.boot.nacos.config.util.NacosConfigLoaderFactory;
|
||||
import com.alibaba.nacos.api.config.ConfigService;
|
||||
import com.alibaba.nacos.api.config.ConfigType;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.client.config.NacosConfigService;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.util.Properties;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* @ClassName: NacosConfigLoaderFactoryTest
|
||||
* @Author: ChenHao26
|
||||
* @Date: 2022/8/12 16:42
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@TestPropertySource(properties = { "nacos.config.server-addr=localhost" })
|
||||
@SpringBootTest(classes = { NacosConfigAutoConfiguration.class })
|
||||
public class NacosConfigLoaderFactoryTest {
|
||||
|
||||
private NacosConfigProperties nacosConfigProperties;
|
||||
|
||||
private Properties globalProperties;
|
||||
|
||||
private Function<Properties, ConfigService> builder;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
nacosConfigProperties = new NacosConfigProperties();
|
||||
nacosConfigProperties.setServerAddr("localhost");
|
||||
nacosConfigProperties.setUsername("nacos");
|
||||
nacosConfigProperties.setPassword("nacos");
|
||||
nacosConfigProperties.setMaxRetry("4");
|
||||
nacosConfigProperties.setType(ConfigType.TEXT);
|
||||
nacosConfigProperties.setDataId("xiaomi");
|
||||
nacosConfigProperties.setGroup("group01");
|
||||
nacosConfigProperties.setAutoRefresh(true);
|
||||
nacosConfigProperties.setEndpoint("localhost");
|
||||
globalProperties = new Properties();
|
||||
globalProperties.setProperty("maxRetry","3");
|
||||
globalProperties.setProperty("content","key=01");
|
||||
globalProperties.setProperty("endpoint","localhost");
|
||||
builder = properties -> {
|
||||
try {
|
||||
return new NacosConfigService(globalProperties);
|
||||
} catch (NacosException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSingleton() {
|
||||
NacosConfigLoader singleton = NacosConfigLoaderFactory.getSingleton(builder);
|
||||
NacosConfigLoader singleton2 = NacosConfigLoaderFactory.getSingleton(builder);
|
||||
// Verify that it is the same object
|
||||
Assert.assertEquals(singleton2, singleton);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
* 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.util;
|
||||
|
||||
import com.alibaba.boot.nacos.autoconfigure.NacosConfigEnvironmentProcessorTest;
|
||||
import com.alibaba.boot.nacos.config.autoconfigure.NacosConfigAutoConfiguration;
|
||||
import com.alibaba.boot.nacos.config.properties.NacosConfigProperties;
|
||||
import com.alibaba.boot.nacos.config.util.NacosConfigLoader;
|
||||
import com.alibaba.nacos.api.config.ConfigService;
|
||||
import com.alibaba.nacos.api.config.ConfigType;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.client.config.NacosConfigService;
|
||||
import com.alibaba.nacos.client.utils.LogUtils;
|
||||
import com.alibaba.nacos.spring.core.env.NacosPropertySourcePostProcessor;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* @ClassName: NacosConfigLoaderTest
|
||||
* @Author: ChenHao26
|
||||
* @Date: 2022/8/12 16:12
|
||||
*/
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@TestPropertySource(properties = { "nacos.config.server-addr=localhost" })
|
||||
@SpringBootTest(classes = { NacosConfigAutoConfiguration.class })
|
||||
public class NacosConfigLoaderTest {
|
||||
|
||||
private NacosConfigLoader nacosConfigLoader;
|
||||
|
||||
private NacosConfigProperties nacosConfigProperties;
|
||||
|
||||
private Properties globalProperties;
|
||||
|
||||
@Autowired
|
||||
private ConfigurableEnvironment environment;
|
||||
|
||||
private Function<Properties, ConfigService> builder;
|
||||
|
||||
private List<NacosConfigLoader.DeferNacosPropertySource> nacosPropertySources;
|
||||
|
||||
private static final Logger LOGGER = LogUtils.logger(NacosConfigEnvironmentProcessorTest.class);
|
||||
|
||||
private NacosPropertySourcePostProcessor nacosPropertySourcePostProcessor;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
nacosConfigProperties = new NacosConfigProperties();
|
||||
nacosConfigProperties.setServerAddr("localhost");
|
||||
nacosConfigProperties.setUsername("nacos");
|
||||
nacosConfigProperties.setPassword("nacos");
|
||||
nacosConfigProperties.setMaxRetry("4");
|
||||
nacosConfigProperties.setType(ConfigType.TEXT);
|
||||
nacosConfigProperties.setDataId("xiaomi");
|
||||
nacosConfigProperties.setGroup("group01");
|
||||
nacosConfigProperties.setAutoRefresh(true);
|
||||
nacosConfigProperties.setEndpoint("localhost");
|
||||
globalProperties = new Properties();
|
||||
globalProperties.setProperty("maxRetry","3");
|
||||
globalProperties.setProperty("content","key=01");
|
||||
globalProperties.setProperty("endpoint","localhost");
|
||||
builder = properties -> {
|
||||
try {
|
||||
return new NacosConfigService(globalProperties);
|
||||
} catch (NacosException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
};
|
||||
nacosPropertySources = new LinkedList<>();
|
||||
nacosConfigLoader = new NacosConfigLoader(builder);
|
||||
nacosPropertySourcePostProcessor = new NacosPropertySourcePostProcessor();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildGlobalNacosProperties() {
|
||||
Properties properties = nacosConfigLoader.buildGlobalNacosProperties(environment, nacosConfigProperties);
|
||||
LOGGER.info("buildGlobalNacosProperties properties : {}", properties);
|
||||
Assert.assertNotNull(properties);
|
||||
Assert.assertEquals(properties.size(), 6);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addListenerIfAutoRefreshed() {
|
||||
nacosConfigLoader.addListenerIfAutoRefreshed();
|
||||
List<NacosConfigLoader.DeferNacosPropertySource> propertySources = nacosConfigLoader.getNacosPropertySources();
|
||||
Assert.assertEquals(propertySources.size(), 0);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
*
|
||||
* * 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.util;
|
||||
|
||||
import com.alibaba.boot.nacos.config.autoconfigure.NacosConfigAutoConfiguration;
|
||||
import com.alibaba.boot.nacos.config.properties.NacosConfigProperties;
|
||||
import com.alibaba.boot.nacos.config.util.NacosConfigPropertiesUtils;
|
||||
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.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* {@link NacosConfigPropertiesUtils} Test
|
||||
* @ClassName: NacosConfigPropertiesUtilsTest
|
||||
* @Author: SuperZ1999
|
||||
* @Date: 2023/9/28
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = { NacosConfigAutoConfiguration.class })
|
||||
@TestPropertySource(properties = {
|
||||
"nacos.config.server-addr=8.8.8.8",
|
||||
"nacos.config.password=123456"
|
||||
})
|
||||
public class NacosConfigPropertiesUtilsTest {
|
||||
@Autowired
|
||||
private ConfigurableEnvironment environment;
|
||||
|
||||
@Test
|
||||
public void testBuildNacosConfigProperties() {
|
||||
NacosConfigProperties properties = NacosConfigPropertiesUtils.buildNacosConfigProperties(environment);
|
||||
Assert.assertEquals(properties.getServerAddr(), "8.8.8.8");
|
||||
Assert.assertEquals(properties.getPassword(), "123456");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* 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.util;
|
||||
|
||||
import com.alibaba.boot.nacos.config.autoconfigure.NacosConfigAutoConfiguration;
|
||||
import com.alibaba.boot.nacos.config.util.NacosPropertiesBuilder;
|
||||
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.core.env.Environment;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @ClassName: NacosPropertiesBuilderTest
|
||||
* @Author: ChenHao26
|
||||
* @Date: 2022/8/12 16:49
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@TestPropertySource(properties = { "nacos.config.server-addr=localhost" })
|
||||
@SpringBootTest(classes = { NacosConfigAutoConfiguration.class })
|
||||
public class NacosPropertiesBuilderTest {
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
@Test
|
||||
public void testBuildNacosProperties() {
|
||||
String serverAddr = "${nacos.config.server-addr}";
|
||||
String namespaceId = "namespaceId";
|
||||
String secretKey = "secretKey";
|
||||
String ramRoleName = "ramRoleName";
|
||||
String configLongPollTimeout = "configLongPollTimeout";
|
||||
String configRetryTimeout = "configRetryTimeout";
|
||||
String maxRetry = "maxRetry";
|
||||
String enableRemoteSyncConfig = "enableRemoteSyncConfig";
|
||||
String username = "nacos";
|
||||
String password = "password";
|
||||
Properties properties = NacosPropertiesBuilder.buildNacosProperties(environment, serverAddr, namespaceId, secretKey,
|
||||
"ak", ramRoleName, configLongPollTimeout, configRetryTimeout, maxRetry, null,enableRemoteSyncConfig, true,
|
||||
username, password);
|
||||
Assert.assertEquals(properties.size(), 12);
|
||||
Assert.assertEquals(properties.get("serverAddr"), "localhost");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMerge() {
|
||||
Properties sourceProperties = new Properties();
|
||||
sourceProperties.put("name", "SuperZ1999");
|
||||
sourceProperties.put("age", 24);
|
||||
|
||||
Properties targetProperties = new Properties();
|
||||
targetProperties.put("age", 99);
|
||||
|
||||
NacosPropertiesBuilder.merge(targetProperties, sourceProperties);
|
||||
Assert.assertEquals(targetProperties.get("name"), "SuperZ1999");
|
||||
Assert.assertEquals(targetProperties.get("age"), 99);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* 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.util.editor;
|
||||
|
||||
import com.alibaba.boot.nacos.config.util.editor.NacosCharSequenceEditor;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @ClassName: NacosCharSequenceEditorTest
|
||||
* @Author: ChenHao26
|
||||
* @Date: 2022/8/12 17:00
|
||||
*/
|
||||
public class NacosCharSequenceEditorTest {
|
||||
|
||||
public NacosCharSequenceEditor nacosCharSequenceEditor;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
nacosCharSequenceEditor = new NacosCharSequenceEditor();
|
||||
|
||||
}
|
||||
@Test
|
||||
public void setValue() {
|
||||
nacosCharSequenceEditor.setValue("nacosTest");
|
||||
String asText = nacosCharSequenceEditor.getAsText();
|
||||
Assert.assertEquals(asText,"nacosTest");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAsText() {
|
||||
String str = nacosCharSequenceEditor.getAsText();
|
||||
Assert.assertEquals(str, "null");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
*
|
||||
* * 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.util.editor;
|
||||
|
||||
import com.alibaba.boot.nacos.config.util.editor.NacosCustomBooleanEditor;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* {@link NacosCustomBooleanEditor} Test
|
||||
* @ClassName: NacosCustomBooleanEditorTest
|
||||
* @Author: SuperZ1999
|
||||
* @Date: 2023/9/28
|
||||
*/
|
||||
public class NacosCustomBooleanEditorTest {
|
||||
@Test
|
||||
public void testAllowEmpty() {
|
||||
NacosCustomBooleanEditor booleanEditor = new NacosCustomBooleanEditor(true);
|
||||
booleanEditor.setValue("");
|
||||
Assert.assertEquals(booleanEditor.getAsText(), "false");
|
||||
|
||||
booleanEditor.setValue("true");
|
||||
Assert.assertEquals(booleanEditor.getAsText(), "true");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testNotAllowEmpty() {
|
||||
NacosCustomBooleanEditor booleanEditor = new NacosCustomBooleanEditor(false);
|
||||
booleanEditor.setValue("true");
|
||||
Assert.assertEquals(booleanEditor.getAsText(), "true");
|
||||
|
||||
booleanEditor.setValue("");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomBooleanString() {
|
||||
NacosCustomBooleanEditor booleanEditor = new NacosCustomBooleanEditor("TRUE", "FALSE", true);
|
||||
booleanEditor.setValue("");
|
||||
Assert.assertEquals(booleanEditor.getAsText(), "FALSE");
|
||||
|
||||
booleanEditor.setValue("TRUE");
|
||||
Assert.assertEquals(booleanEditor.getAsText(), "TRUE");
|
||||
|
||||
booleanEditor.setValue("false");
|
||||
Assert.assertEquals(booleanEditor.getAsText(), "FALSE");
|
||||
}
|
||||
}
|
|
@ -18,7 +18,7 @@
|
|||
<parent>
|
||||
<groupId>com.alibaba.boot</groupId>
|
||||
<artifactId>nacos-spring-boot-parent</artifactId>
|
||||
<version>0.9.0</version>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../nacos-spring-boot-parent</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -34,13 +34,24 @@
|
|||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<scope>true</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Nacos -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-spring-context</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
<version>${nacos.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@ -53,5 +64,10 @@
|
|||
<artifactId>nacos-spring-boot-base</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.boot</groupId>
|
||||
<artifactId>nacos-spring-boot-aot</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
<parent>
|
||||
<artifactId>nacos-spring-boot-parent</artifactId>
|
||||
<groupId>com.alibaba.boot</groupId>
|
||||
<version>0.9.0</version>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../nacos-spring-boot-parent/pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -81,7 +81,20 @@
|
|||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-spring-context</artifactId>
|
||||
<optional>true</optional>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
<version>${nacos.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- Test Dependencies -->
|
||||
<dependency>
|
||||
|
|
|
@ -16,14 +16,13 @@
|
|||
*/
|
||||
package com.alibaba.boot.nacos.discovery.actuate.autoconfigure;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint;
|
||||
import com.alibaba.boot.nacos.discovery.actuate.endpoint.NacosDiscoveryEndpoint;
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||
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}
|
||||
*
|
||||
|
@ -35,7 +34,7 @@ public class NacosDiscoveryEndpointsAutoConfiguration {
|
|||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnEnabledEndpoint
|
||||
@ConditionalOnAvailableEndpoint
|
||||
public NacosDiscoveryEndpoint nacosDiscoveryEndpoint() {
|
||||
return new NacosDiscoveryEndpoint();
|
||||
}
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
*/
|
||||
package com.alibaba.boot.nacos.discovery.actuate.autoconfigure;
|
||||
|
||||
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.endpoint.EndpointAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
|
||||
import org.springframework.boot.actuate.health.HealthIndicator;
|
||||
|
@ -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
|
||||
*
|
||||
|
|
|
@ -16,26 +16,26 @@
|
|||
*/
|
||||
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 com.alibaba.boot.nacos.common.PropertiesUtils;
|
||||
import com.alibaba.boot.nacos.discovery.NacosDiscoveryConstants;
|
||||
import com.alibaba.nacos.api.naming.NamingService;
|
||||
import com.alibaba.nacos.common.utils.JacksonUtils;
|
||||
import com.alibaba.nacos.spring.factory.CacheableEventPublishingNacosServiceFactory;
|
||||
import com.alibaba.nacos.spring.factory.NacosServiceFactory;
|
||||
import com.alibaba.nacos.spring.util.NacosUtils;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
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 static com.alibaba.nacos.spring.util.NacosBeanUtils.DISCOVERY_GLOBAL_NACOS_PROPERTIES_BEAN_NAME;
|
||||
|
||||
/**
|
||||
* Actuator {@link Endpoint} to expose Nacos Discovery Meta Data
|
||||
|
@ -53,26 +53,27 @@ public class NacosDiscoveryEndpoint {
|
|||
|
||||
@ReadOperation
|
||||
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();
|
||||
ArrayNode array = JacksonUtils.createEmptyArrayNode();
|
||||
for (NamingService namingService : nacosServiceFactory.getNamingServices()) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
ObjectNode jsonObject = JacksonUtils.createEmptyJsonNode();
|
||||
try {
|
||||
jsonObject.put("servicesOfServer",
|
||||
jsonObject.putPOJO("servicesOfServer",
|
||||
namingService.getServicesOfServer(0, PAGE_SIZE));
|
||||
jsonObject.put("subscribeServices", namingService.getSubscribeServices());
|
||||
jsonObject.putPOJO("subscribeServices", namingService.getSubscribeServices());
|
||||
array.add(jsonObject);
|
||||
}
|
||||
catch (NacosException e) {
|
||||
catch (Exception e) {
|
||||
jsonObject.put("serverStatus", namingService.getServerStatus() + ": "
|
||||
+ e.getErrCode() + NacosUtils.SEPARATOR + e.getErrMsg());
|
||||
+ NacosUtils.SEPARATOR + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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.nacos.api.naming.NamingService;
|
||||
import com.alibaba.nacos.common.utils.JacksonUtils;
|
||||
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,17 +47,18 @@ 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;
|
||||
Properties properties = nacosServiceMetaData.getProperties();
|
||||
builder.withDetail(
|
||||
JSON.toJSONString(
|
||||
JacksonUtils.toJson(
|
||||
PropertiesUtils.extractSafeProperties(properties)),
|
||||
namingService.getServerStatus());
|
||||
}
|
||||
if (!namingService.getServerStatus().toLowerCase().equals(UP_STATUS)) {
|
||||
if (!namingService.getServerStatus().equalsIgnoreCase(UP_STATUS)) {
|
||||
builder.down();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
com.alibaba.boot.nacos.discovery.actuate.autoconfigure.NacosDiscoveryEndpointsAutoConfiguration
|
||||
com.alibaba.boot.nacos.discovery.actuate.autoconfigure.NacosDiscoveryHealthIndicatorAutoConfiguration
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
*
|
||||
* * 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.actuate.autoconfigure;
|
||||
|
||||
import com.alibaba.boot.nacos.discovery.actuate.autoconfigure.NacosDiscoveryEndpointsAutoConfiguration;
|
||||
import com.alibaba.boot.nacos.discovery.actuate.endpoint.NacosDiscoveryEndpoint;
|
||||
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.context.ApplicationContext;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* {@link NacosDiscoveryEndpointsAutoConfiguration} Test
|
||||
* @ClassName: NacosDiscoveryEndpointsAutoConfigurationTest
|
||||
* @Author: SuperZ1999
|
||||
* @Date: 2023/9/28
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = {NacosDiscoveryEndpointsAutoConfiguration.class})
|
||||
@TestPropertySource(properties = {
|
||||
"management.endpoints.web.exposure.include=nacos-discovery"
|
||||
})
|
||||
public class NacosDiscoveryEndpointsAutoConfigurationTest {
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void testNacosDiscoveryEndpointBean() {
|
||||
Assert.assertNotNull(context.getBean(NacosDiscoveryEndpoint.class));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
*
|
||||
* * 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.actuate.autoconfigure;
|
||||
|
||||
import com.alibaba.boot.nacos.discovery.actuate.autoconfigure.NacosDiscoveryHealthIndicatorAutoConfiguration;
|
||||
import com.alibaba.boot.nacos.discovery.actuate.health.NacosDiscoveryHealthIndicator;
|
||||
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.context.ApplicationContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* {@link NacosDiscoveryHealthIndicatorAutoConfiguration} Test
|
||||
* @ClassName: NacosDiscoveryHealthIndicatorAutoConfigurationTest
|
||||
* @Author: SuperZ1999
|
||||
* @Date: 2023/9/28
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = {NacosDiscoveryHealthIndicatorAutoConfiguration.class})
|
||||
public class NacosDiscoveryHealthIndicatorAutoConfigurationTest {
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void testNacosConfigHealthIndicatorBean() {
|
||||
Assert.assertNotNull(context.getBean(NacosDiscoveryHealthIndicator.class));
|
||||
}
|
||||
}
|
|
@ -19,18 +19,16 @@ 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 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
|
||||
*
|
||||
|
@ -38,7 +36,6 @@ import com.alibaba.nacos.api.PropertyKeyConst;
|
|||
* @see NacosDiscoveryEndpoint
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@TestPropertySource(properties = { "nacos.discovery.server-addr=localhost" })
|
||||
@SpringBootTest(classes = { NacosDiscoveryEndpoint.class,
|
||||
NacosDiscoveryAutoConfiguration.class })
|
||||
public class NacosDiscoveryEndpointTest {
|
||||
|
@ -53,8 +50,7 @@ public class NacosDiscoveryEndpointTest {
|
|||
HashMap nacosDiscoveryGlobalProperties = (HashMap) metadata
|
||||
.get("nacosDiscoveryGlobalProperties");
|
||||
|
||||
Assert.assertEquals("localhost",
|
||||
nacosDiscoveryGlobalProperties.get(PropertyKeyConst.SERVER_ADDR));
|
||||
Assert.assertNotNull(nacosDiscoveryGlobalProperties);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
nacos.discovery.serverAddr = "127.0.0.1:8848"
|
|
@ -18,7 +18,7 @@
|
|||
<parent>
|
||||
<groupId>com.alibaba.boot</groupId>
|
||||
<artifactId>nacos-spring-boot-parent</artifactId>
|
||||
<version>0.9.0</version>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../nacos-spring-boot-parent</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -54,11 +54,30 @@
|
|||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-spring-context</artifactId>
|
||||
<optional>true</optional>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
<version>${nacos.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.boot</groupId>
|
||||
<artifactId>nacos-spring-boot-base</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.boot</groupId>
|
||||
<artifactId>nacos-spring-boot-base</artifactId>
|
||||
<artifactId>nacos-spring-boot-aot</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
|
|
|
@ -25,9 +25,10 @@ import com.alibaba.nacos.spring.context.annotation.discovery.EnableNacosDiscover
|
|||
*/
|
||||
public interface NacosDiscoveryConstants {
|
||||
|
||||
String PREFIX = "nacos.discovery";
|
||||
|
||||
String ENDPOINT_PREFIX = "nacos-discovery";
|
||||
|
||||
String ENABLED = EnableNacosDiscovery.DISCOVERY_PREFIX + "enabled";
|
||||
String ENABLED = EnableNacosDiscovery.DISCOVERY_PREFIX + "enabled";
|
||||
|
||||
String PREFIX = "nacos.discovery";
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* 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.2.4
|
||||
*/
|
||||
public class AutoDeregisterException extends RuntimeException {
|
||||
|
||||
public AutoDeregisterException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public AutoDeregisterException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* 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.2.3
|
||||
*/
|
||||
public class AutoRegisterException extends RuntimeException {
|
||||
|
||||
public AutoRegisterException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public AutoRegisterException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
|
@ -16,17 +16,20 @@
|
|||
*/
|
||||
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.aot.context.EnableNacosDiscoveryAotProcessor;
|
||||
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 org.springframework.context.annotation.Import;
|
||||
|
||||
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}
|
||||
|
@ -38,6 +41,12 @@ import com.alibaba.nacos.spring.context.annotation.discovery.EnableNacosDiscover
|
|||
@EnableNacosDiscovery
|
||||
@EnableConfigurationProperties(value = NacosDiscoveryProperties.class)
|
||||
@ConditionalOnClass(name = "org.springframework.boot.context.properties.bind.Binder")
|
||||
@Import(EnableNacosDiscoveryAotProcessor.class)
|
||||
public class NacosDiscoveryAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public NacosDiscoveryAutoRegister discoveryAutoRegister() {
|
||||
return new NacosDiscoveryAutoRegister();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.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.api.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.web.server.WebServer;
|
||||
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.2.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 WebServer webServer;
|
||||
|
||||
@Value("${spring.application.name:}")
|
||||
private String applicationName;
|
||||
|
||||
public NacosDiscoveryAutoDeregister(NacosDiscoveryProperties discoveryProperties,
|
||||
WebServer 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 = register.getServiceName();
|
||||
|
||||
if (StringUtils.isEmpty(serviceName)){
|
||||
if (StringUtils.isEmpty(applicationName)){
|
||||
throw new AutoDeregisterException("serviceName notNull");
|
||||
}
|
||||
serviceName = applicationName;
|
||||
}
|
||||
|
||||
try {
|
||||
namingService.deregisterInstance(serviceName, register.getGroupName(),
|
||||
register);
|
||||
logger.info("Finished auto deregister service : {}, ip : {}, port : {}",
|
||||
serviceName, register.getIp(), register.getPort());
|
||||
}
|
||||
catch (NacosException e) {
|
||||
throw new AutoDeregisterException(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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.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.api.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.web.context.WebServerInitializedEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
|
||||
* @since 0.2.3
|
||||
*/
|
||||
@Component
|
||||
public class NacosDiscoveryAutoRegister
|
||||
implements ApplicationListener<WebServerInitializedEvent> {
|
||||
|
||||
private static final Logger logger = LoggerFactory
|
||||
.getLogger(NacosDiscoveryAutoRegister.class);
|
||||
|
||||
@NacosInjected
|
||||
private NamingService namingService;
|
||||
|
||||
@Autowired
|
||||
private NacosDiscoveryProperties discoveryProperties;
|
||||
|
||||
@Value("${spring.application.name:}")
|
||||
private String applicationName;
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(WebServerInitializedEvent 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.getWebServer().getPort());
|
||||
}
|
||||
|
||||
register.getMetadata().put("preserved.register.source", "SPRING_BOOT");
|
||||
|
||||
register.setInstanceId("");
|
||||
|
||||
String serviceName = register.getServiceName();
|
||||
|
||||
if (StringUtils.isEmpty(serviceName)){
|
||||
if (StringUtils.isEmpty(applicationName)){
|
||||
throw new AutoRegisterException("serviceName notNull");
|
||||
}
|
||||
serviceName = applicationName;
|
||||
}
|
||||
|
||||
try {
|
||||
namingService.registerInstance(serviceName, register.getGroupName(),
|
||||
register);
|
||||
logger.info("Finished auto register service : {}, ip : {}, port : {}",
|
||||
serviceName, register.getIp(), register.getPort());
|
||||
} catch (NacosException e) {
|
||||
throw new AutoRegisterException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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,101 @@ 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;
|
||||
}
|
||||
private String username;
|
||||
|
||||
public void setContextPath(String contextPath) {
|
||||
this.contextPath = contextPath;
|
||||
}
|
||||
private String password;
|
||||
|
||||
public String getClusterName() {
|
||||
return clusterName;
|
||||
}
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setClusterName(String clusterName) {
|
||||
this.clusterName = clusterName;
|
||||
}
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getEndpoint() {
|
||||
return endpoint;
|
||||
}
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setEndpoint(String endpoint) {
|
||||
this.endpoint = endpoint;
|
||||
}
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getNamespace() {
|
||||
return namespace;
|
||||
}
|
||||
public String getServerAddr() {
|
||||
return serverAddr;
|
||||
}
|
||||
|
||||
public void setNamespace(String namespace) {
|
||||
this.namespace = namespace;
|
||||
}
|
||||
public void setServerAddr(String serverAddr) {
|
||||
Assert.notNull(serverAddr, "nacos discovery server-addr must not be null");
|
||||
this.serverAddr = serverAddr;
|
||||
}
|
||||
|
||||
public String getAccessKey() {
|
||||
return accessKey;
|
||||
}
|
||||
public String getContextPath() {
|
||||
return contextPath;
|
||||
}
|
||||
|
||||
public void setAccessKey(String accessKey) {
|
||||
this.accessKey = accessKey;
|
||||
}
|
||||
public void setContextPath(String contextPath) {
|
||||
this.contextPath = contextPath;
|
||||
}
|
||||
|
||||
public String getSecretKey() {
|
||||
return secretKey;
|
||||
}
|
||||
public String getClusterName() {
|
||||
return clusterName;
|
||||
}
|
||||
|
||||
public void setSecretKey(String secretKey) {
|
||||
this.secretKey = secretKey;
|
||||
}
|
||||
public void setClusterName(String clusterName) {
|
||||
this.clusterName = clusterName;
|
||||
}
|
||||
|
||||
public String getEndpoint() {
|
||||
return endpoint;
|
||||
}
|
||||
|
||||
public void setEndpoint(String endpoint) {
|
||||
this.endpoint = endpoint;
|
||||
}
|
||||
|
||||
public String getNamespace() {
|
||||
return namespace;
|
||||
}
|
||||
|
||||
public void setNamespace(String namespace) {
|
||||
this.namespace = namespace;
|
||||
}
|
||||
|
||||
public String getAccessKey() {
|
||||
return accessKey;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.2.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;
|
||||
}
|
||||
}
|
|
@ -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"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
{
|
||||
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.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.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.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.secret-key",
|
||||
description: "the secretkey of Alibaba Cloud Account",
|
||||
type: "java.lang.String"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,2 +1,2 @@
|
|||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
com.alibaba.boot.nacos.discovery.autoconfigure.NacosDiscoveryAutoConfiguration
|
||||
com.alibaba.boot.nacos.discovery.autoconfigure.NacosDiscoveryAutoConfiguration
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
com.alibaba.boot.nacos.discovery.autoconfigure.NacosDiscoveryAutoConfiguration
|
|
@ -19,11 +19,16 @@ package com.alibaba.boot.nacos.autoconfigure;
|
|||
import java.util.Properties;
|
||||
|
||||
import com.alibaba.boot.nacos.discovery.autoconfigure.NacosDiscoveryAutoConfiguration;
|
||||
import com.alibaba.boot.nacos.discovery.autoconfigure.NacosDiscoveryAutoRegister;
|
||||
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 +36,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 +43,50 @@ 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 testNacosDiscoveryGlobalBean() {
|
||||
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 testNacosConfigGlobalBean() {
|
||||
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));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddNacosDiscoveryAutoRegister() {
|
||||
Assert.assertNotNull(applicationContext.getBean(NacosDiscoveryAutoRegister.class));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
<parent>
|
||||
<groupId>com.alibaba.boot</groupId>
|
||||
<artifactId>nacos-spring-boot-parent</artifactId>
|
||||
<version>0.9.0</version>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../nacos-spring-boot-parent</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -34,13 +34,24 @@
|
|||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<scope>true</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Nacos -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-spring-context</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
<version>${nacos.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@ -53,5 +64,10 @@
|
|||
<artifactId>nacos-spring-boot-base</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.boot</groupId>
|
||||
<artifactId>nacos-spring-boot-aot</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
<?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
|
||||
~ *
|
||||
~ * 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.
|
||||
~ */
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.alibaba.boot</groupId>
|
||||
<artifactId>nacos-spring-boot-parent</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../nacos-spring-boot-parent</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>nacos-spring-boot-aot</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Nacos Spring Boot Aot</name>
|
||||
<description>Nacos Spring Boot Aot</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-beans</artifactId>
|
||||
<version>${spring6.framework.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
<version>${spring6.framework.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>${spring6.framework.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-spring-context</artifactId>
|
||||
<version>${nacos-spring-context.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
<version>${nacos.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
*
|
||||
* * 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.aot.context;
|
||||
|
||||
import com.alibaba.boot.nacos.aot.util.AotDetector;
|
||||
import com.alibaba.nacos.spring.context.annotation.config.EnableNacosConfig;
|
||||
import com.alibaba.nacos.spring.context.annotation.config.NacosConfigBeanDefinitionRegistrar;
|
||||
import com.alibaba.nacos.spring.core.env.NacosPropertySourcePostProcessor;
|
||||
import com.alibaba.nacos.spring.util.NacosBeanUtils;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.context.EnvironmentAware;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static com.alibaba.nacos.spring.util.NacosBeanUtils.*;
|
||||
|
||||
/**
|
||||
* {@link EnableNacosConfig} AotProcessor
|
||||
* Except for the operation of registering BeanDefinition, all other operations in {@link NacosConfigBeanDefinitionRegistrar} must be done here
|
||||
* because spring will not call {@link NacosConfigBeanDefinitionRegistrar#registerBeanDefinitions} in AOT.
|
||||
* @author SuperZ1999
|
||||
*/
|
||||
public class EnableNacosConfigAotProcessor implements BeanDefinitionRegistryPostProcessor, EnvironmentAware, BeanFactoryAware {
|
||||
private Environment environment;
|
||||
|
||||
private BeanFactory beanFactory;
|
||||
|
||||
@Override
|
||||
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
|
||||
if (!AotDetector.useGeneratedArtifacts()) {
|
||||
return;
|
||||
}
|
||||
DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) this.beanFactory;
|
||||
Map<String, Object> beansWithAnnotation = beanFactory.getBeansWithAnnotation(EnableNacosConfig.class);
|
||||
Object[] beans = beansWithAnnotation.values().toArray();
|
||||
if (beans.length != 0) {
|
||||
// only handle the first one
|
||||
Class<?> aClass = beans[0].getClass();
|
||||
if (aClass.getAnnotation(EnableNacosConfig.class) == null) {
|
||||
// cglib proxy object
|
||||
aClass = aClass.getSuperclass();
|
||||
}
|
||||
AnnotationMetadata annotationMetadata = AnnotationMetadata.introspect(aClass);
|
||||
AnnotationAttributes attributes = AnnotationAttributes
|
||||
.fromMap(annotationMetadata
|
||||
.getAnnotationAttributes(EnableNacosConfig.class.getName()));
|
||||
|
||||
// Register Global Nacos Properties Bean
|
||||
registerGlobalNacosProperties(attributes, registry, environment,
|
||||
CONFIG_GLOBAL_NACOS_PROPERTIES_BEAN_NAME);
|
||||
}
|
||||
|
||||
registerNacosConfigListenerExecutor(registry, environment);
|
||||
// replace NacosPropertySourcePostProcessor with NacosPropertySourcePostProcessorForAot
|
||||
if (registry.containsBeanDefinition(NacosPropertySourcePostProcessor.BEAN_NAME)) {
|
||||
registry.removeBeanDefinition(NacosPropertySourcePostProcessor.BEAN_NAME);
|
||||
}
|
||||
NacosBeanUtils.registerInfrastructureBeanIfAbsent(registry, NacosPropertySourcePostProcessorForAot.BEAN_NAME,
|
||||
NacosPropertySourcePostProcessorForAot.class);
|
||||
// Invoke NacosPropertySourcePostProcessor immediately
|
||||
// in order to enhance the precedence of @NacosPropertySource process
|
||||
invokeNacosPropertySourcePostProcessor(this.beanFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnvironment(Environment environment) {
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
||||
this.beanFactory = beanFactory;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
*
|
||||
* * 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.aot.context;
|
||||
|
||||
import com.alibaba.boot.nacos.aot.util.AotDetector;
|
||||
import com.alibaba.nacos.spring.context.annotation.discovery.EnableNacosDiscovery;
|
||||
import com.alibaba.nacos.spring.context.annotation.discovery.NacosDiscoveryBeanDefinitionRegistrar;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.context.EnvironmentAware;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static com.alibaba.nacos.spring.util.NacosBeanUtils.*;
|
||||
|
||||
/**
|
||||
* {@link EnableNacosDiscovery} AotProcessor
|
||||
* Except for the operation of registering BeanDefinition, all other operations in {@link NacosDiscoveryBeanDefinitionRegistrar} must be done here
|
||||
* because spring will not call {@link NacosDiscoveryBeanDefinitionRegistrar#registerBeanDefinitions} in AOT.
|
||||
* @author SuperZ1999
|
||||
*/
|
||||
public class EnableNacosDiscoveryAotProcessor implements BeanDefinitionRegistryPostProcessor, EnvironmentAware, BeanFactoryAware {
|
||||
private Environment environment;
|
||||
|
||||
private BeanFactory beanFactory;
|
||||
|
||||
@Override
|
||||
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
|
||||
if (!AotDetector.useGeneratedArtifacts()) {
|
||||
return;
|
||||
}
|
||||
DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) this.beanFactory;
|
||||
Map<String, Object> beansWithAnnotation = beanFactory.getBeansWithAnnotation(EnableNacosDiscovery.class);
|
||||
Object[] beans = beansWithAnnotation.values().toArray();
|
||||
if (beans.length != 0) {
|
||||
// only handle the first one
|
||||
Class<?> aClass = beans[0].getClass();
|
||||
if (aClass.getAnnotation(EnableNacosDiscovery.class) == null) {
|
||||
// cglib proxy object
|
||||
aClass = aClass.getSuperclass();
|
||||
}
|
||||
AnnotationMetadata annotationMetadata = AnnotationMetadata.introspect(aClass);
|
||||
AnnotationAttributes attributes = AnnotationAttributes
|
||||
.fromMap(annotationMetadata
|
||||
.getAnnotationAttributes(EnableNacosDiscovery.class.getName()));
|
||||
|
||||
// Register Global Nacos Properties Bean
|
||||
registerGlobalNacosProperties(attributes, registry, environment,
|
||||
DISCOVERY_GLOBAL_NACOS_PROPERTIES_BEAN_NAME);
|
||||
registerGlobalNacosProperties(attributes, registry, environment,
|
||||
MAINTAIN_GLOBAL_NACOS_PROPERTIES_BEAN_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnvironment(Environment environment) {
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
||||
this.beanFactory = beanFactory;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
*
|
||||
* * 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.aot.context;
|
||||
|
||||
import com.alibaba.boot.nacos.aot.util.AotDetector;
|
||||
import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource;
|
||||
import com.alibaba.nacos.spring.core.env.AbstractNacosPropertySourceBuilder;
|
||||
import com.alibaba.nacos.spring.core.env.NacosPropertySourcePostProcessor;
|
||||
import com.alibaba.spring.util.BeanUtils;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.alibaba.nacos.spring.util.NacosBeanUtils.getConfigServiceBeanBuilder;
|
||||
|
||||
public class NacosPropertySourcePostProcessorForAot extends NacosPropertySourcePostProcessor {
|
||||
@Override
|
||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
|
||||
throws BeansException {
|
||||
String[] abstractNacosPropertySourceBuilderBeanNames = BeanUtils
|
||||
.getBeanNames(beanFactory, AbstractNacosPropertySourceBuilder.class);
|
||||
|
||||
this.nacosPropertySourceBuilders = new ArrayList<AbstractNacosPropertySourceBuilder>(
|
||||
abstractNacosPropertySourceBuilderBeanNames.length);
|
||||
|
||||
for (String beanName : abstractNacosPropertySourceBuilderBeanNames) {
|
||||
this.nacosPropertySourceBuilders.add(beanFactory.getBean(beanName,
|
||||
AbstractNacosPropertySourceBuilder.class));
|
||||
}
|
||||
|
||||
NacosPropertySourcePostProcessor.beanFactory = beanFactory;
|
||||
this.configServiceBeanBuilder = getConfigServiceBeanBuilder(beanFactory);
|
||||
|
||||
if (AotDetector.useGeneratedArtifacts()) {
|
||||
// the type of all BeanDefinitions is RootBeanDefinition in AOT, but what we need is AnnotatedGenericBeanDefinition.
|
||||
Map<String, Object> beansWithAnnotation = beanFactory.getBeansWithAnnotation(NacosPropertySource.class);
|
||||
for (Map.Entry<String, Object> entry : beansWithAnnotation.entrySet()) {
|
||||
processPropertySourceForAot(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
String[] beanNames = beanFactory.getBeanDefinitionNames();
|
||||
|
||||
for (String beanName : beanNames) {
|
||||
processPropertySource(beanName, beanFactory);
|
||||
}
|
||||
}
|
||||
|
||||
private void processPropertySourceForAot(String beanName, Object bean) {
|
||||
if (processedBeanNames.contains(beanName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
BeanDefinition beanDefinition = null;
|
||||
Class<?> aClass = bean.getClass();
|
||||
NacosPropertySource[] annotations = aClass.getSuperclass().getAnnotationsByType(NacosPropertySource.class);
|
||||
if (annotations.length != 0) {
|
||||
beanDefinition = new AnnotatedGenericBeanDefinition(aClass.getSuperclass());
|
||||
}
|
||||
annotations = aClass.getAnnotationsByType(NacosPropertySource.class);
|
||||
if (annotations.length != 0) {
|
||||
beanDefinition = new AnnotatedGenericBeanDefinition(aClass);
|
||||
}
|
||||
|
||||
doProcessPropertySource(beanName, beanDefinition);
|
||||
|
||||
processedBeanNames.add(beanName);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
*
|
||||
* * 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.aot.hint;
|
||||
|
||||
import com.alibaba.nacos.api.annotation.NacosInjected;
|
||||
import com.alibaba.nacos.api.config.annotation.NacosValue;
|
||||
import org.springframework.aot.generate.GenerationContext;
|
||||
import org.springframework.beans.factory.aot.BeanRegistrationAotContribution;
|
||||
import org.springframework.beans.factory.aot.BeanRegistrationAotProcessor;
|
||||
import org.springframework.beans.factory.aot.BeanRegistrationCode;
|
||||
import org.springframework.beans.factory.support.RegisteredBean;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* {@link NacosInjected} and {@link NacosValue} AotProcessor
|
||||
* The fields annotated with {@link NacosInjected} or {@link NacosValue} must be added to the reflect-config.json
|
||||
* @author SuperZ1999
|
||||
*/
|
||||
public class NacosAnnotationBeanRegistrationAotProcessor implements BeanRegistrationAotProcessor {
|
||||
@Override
|
||||
public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
|
||||
Class<?> beanClass = registeredBean.getBeanClass();
|
||||
List<Field> fields = new ArrayList<>();
|
||||
ReflectionUtils.doWithFields(beanClass, field -> {
|
||||
NacosInjected injectedAnnotation = field.getDeclaredAnnotation(NacosInjected.class);
|
||||
NacosValue nacosValueAnnotation = field.getDeclaredAnnotation(NacosValue.class);
|
||||
if (injectedAnnotation != null || nacosValueAnnotation != null) {
|
||||
fields.add(field);
|
||||
}
|
||||
});
|
||||
if (fields.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return new AotContribution(fields);
|
||||
}
|
||||
|
||||
private static class AotContribution implements BeanRegistrationAotContribution {
|
||||
private final List<Field> fields;
|
||||
|
||||
public AotContribution() {
|
||||
this.fields = new ArrayList<>();
|
||||
}
|
||||
|
||||
public AotContribution(List<Field> fields) {
|
||||
this.fields = fields;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyTo(GenerationContext generationContext, BeanRegistrationCode beanRegistrationCode) {
|
||||
for (Field field : fields) {
|
||||
generationContext.getRuntimeHints().reflection().registerField(field);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
*
|
||||
* * 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.aot.util;
|
||||
|
||||
import org.springframework.core.NativeDetector;
|
||||
import org.springframework.core.SpringProperties;
|
||||
|
||||
public abstract class AotDetector {
|
||||
|
||||
/**
|
||||
* System property that indicates the application should run with AOT
|
||||
* generated artifacts. If such optimizations are not available, it is
|
||||
* recommended to throw an exception rather than fall back to the regular
|
||||
* runtime behavior.
|
||||
*/
|
||||
public static final String AOT_ENABLED = "spring.aot.enabled";
|
||||
|
||||
/**
|
||||
* Determine whether AOT optimizations must be considered at runtime. This
|
||||
* is mandatory in a native image but can be triggered on the JVM using
|
||||
* the {@value #AOT_ENABLED} Spring property.
|
||||
* @return whether AOT optimizations must be considered
|
||||
*/
|
||||
public static boolean useGeneratedArtifacts() {
|
||||
return (NativeDetector.inNativeImage() || SpringProperties.getFlag(AOT_ENABLED));
|
||||
}
|
||||
|
||||
}
|
|
@ -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.aot.util;
|
||||
|
||||
public abstract class NativeDetector {
|
||||
|
||||
// See https://github.com/oracle/graal/blob/master/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/ImageInfo.java
|
||||
private static final boolean imageCode = (System.getProperty("org.graalvm.nativeimage.imagecode") != null);
|
||||
|
||||
/**
|
||||
* Returns {@code true} if invoked in the context of image building or during image runtime, else {@code false}.
|
||||
*/
|
||||
public static boolean inNativeImage() {
|
||||
return imageCode;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
[
|
||||
{
|
||||
"name": "com.alibaba.boot.nacos.aot.context.NacosPropertySourcePostProcessorForAot",
|
||||
"allDeclaredClasses": true,
|
||||
"allDeclaredMethods": true,
|
||||
"allDeclaredFields": true,
|
||||
"allDeclaredConstructors": true
|
||||
}
|
||||
]
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"resources": {
|
||||
"includes": [
|
||||
{
|
||||
"pattern": "\\QMETA-INF/spring.handlers\\E"
|
||||
},
|
||||
{
|
||||
"pattern": "\\QMETA-INF/spring.schemas\\E"
|
||||
},
|
||||
{
|
||||
"pattern": "\\QMETA-INF/schemas/nacos.xsd\\E"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
org.springframework.beans.factory.aot.BeanRegistrationAotProcessor=\
|
||||
com.alibaba.boot.nacos.aot.hint.NacosAnnotationBeanRegistrationAotProcessor
|
|
@ -18,7 +18,7 @@
|
|||
<parent>
|
||||
<groupId>com.alibaba.boot</groupId>
|
||||
<artifactId>nacos-spring-boot-parent</artifactId>
|
||||
<version>0.9.0</version>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../nacos-spring-boot-parent</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -54,7 +54,20 @@
|
|||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-spring-context</artifactId>
|
||||
<optional>true</optional>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
<version>${nacos.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- Test Dependencies -->
|
||||
<dependency>
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
com.alibaba.boot.nacos.common.NacosFailureAnalyzer
|
|
@ -18,7 +18,7 @@
|
|||
<parent>
|
||||
<groupId>com.alibaba.boot</groupId>
|
||||
<artifactId>nacos-spring-boot-project</artifactId>
|
||||
<version>0.9.0</version>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
@ -35,8 +35,9 @@
|
|||
<java.target.version>1.8</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>2.6.3</spring-boot.version>
|
||||
<spring6.framework.version>6.0.8</spring6.framework.version>
|
||||
<nacos-spring-context.version>2.1.0-RC</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,13 +46,14 @@
|
|||
|
||||
<!-- 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>
|
||||
<nacos.version>2.2.1</nacos.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
|
@ -71,6 +73,18 @@
|
|||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-spring-context</artifactId>
|
||||
<version>${nacos-spring-context.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
<version>${nacos.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@ -79,6 +93,12 @@
|
|||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.boot</groupId>
|
||||
<artifactId>nacos-spring-boot-aot</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.boot</groupId>
|
||||
<artifactId>nacos-config-spring-boot-autoconfigure</artifactId>
|
||||
|
@ -156,6 +176,16 @@
|
|||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.1</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<!-- Used for packaging NOTICE & LICENSE to each sub-module jar-->
|
||||
<resources>
|
||||
|
@ -208,7 +238,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>
|
||||
|
@ -419,4 +449,4 @@
|
|||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
<?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
|
||||
~ *
|
||||
~ * 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.
|
||||
~ */
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.alibaba.boot</groupId>
|
||||
<artifactId>nacos-spring-boot-samples</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>nacos-aot-sample</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Nacos Spring Boot Aot Sample</name>
|
||||
<description>Nacos Spring Boot Aot Sample</description>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>3.0.6</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.boot</groupId>
|
||||
<artifactId>nacos-config-spring-boot-starter</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.boot</groupId>
|
||||
<artifactId>nacos-discovery-spring-boot-starter</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>native</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.graalvm.buildtools</groupId>
|
||||
<artifactId>native-maven-plugin</artifactId>
|
||||
<version>0.9.25</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
|
||||
<mainClass>com.alibaba.boot.nacos.sample.AotApplication</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>process-aot</id>
|
||||
<goals>
|
||||
<goal>process-aot</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
*
|
||||
* * 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 com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
@NacosPropertySource(dataId = "example", autoRefreshed = true)
|
||||
public class AotApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(AotApplication.class, args);
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue