Spring 多模块项目的云客户端配置
Spring cloud client configuration for multiple module project
尽管我已成功设置 spring 云配置 client/server 并将 GIT 作为后端属性回购。但是,对于我的一个客户端代码,我有一个遵循模块结构 (maven) 的基本问题:
客户 1:
common (maven module)
app (maven module)
web (Contains the spring boot application, bootstrap.properties, application.properties)
对于上述结构,我可以从 spring 云配置服务器 read/refresh "web" 模块的属性(因为那是我的 Spring BootApplication 是),但是无法理解如何在其他模块中也注入 configure/inject 属性,例如公共模块或应用程序模块可能有属性。
我尝试在其他模块中添加 bootstrap.properties,它们指向同一个 spring 云配置服务器。但这并没有成功。
Spring 云配置服务器 application.properties:
server.port=8888
spring.cloud.config.server.git.uri=
management.security.enabled=假
网络模块的bootstrap.properties
spring.application.name=测试
spring.cloud.config.uri=http://localhost:8888
management.security.enabled=假
spring.profiles.active=默认,产品
Maven 依赖项(云配置客户端):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>1.4.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
<version>1.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.4.4.RELEASE</version>
</dependency>
请帮助我理解我如何 read/refresh 跨多个模块(如通用、应用程序或 Web)的属性,这些模块将部署在单个 instance/client。
由于您的 common
和 app
模块不是应用程序,它们不会启动,因此不会读取您的 bootstrap.properties 文件。
看看type-safe configuration properties and third party configuration。
您的 common
和 app
模块可以提供多个 类 及其属性。
在 web
模块的 Java 配置中,您可以设置 bootstrap.properties
and/or application.properties
文件中的值与配置 类.
由于 @ConfigurationProperties
注释,Spring Boot 将创建这些配置的常规 bean 类。这样你就可以像任何其他 bean 一样注入你的配置。
希望对您有所帮助! :)
尽管我已成功设置 spring 云配置 client/server 并将 GIT 作为后端属性回购。但是,对于我的一个客户端代码,我有一个遵循模块结构 (maven) 的基本问题:
客户 1:
common (maven module)
app (maven module)
web (Contains the spring boot application, bootstrap.properties, application.properties)
对于上述结构,我可以从 spring 云配置服务器 read/refresh "web" 模块的属性(因为那是我的 Spring BootApplication 是),但是无法理解如何在其他模块中也注入 configure/inject 属性,例如公共模块或应用程序模块可能有属性。
我尝试在其他模块中添加 bootstrap.properties,它们指向同一个 spring 云配置服务器。但这并没有成功。
Spring 云配置服务器 application.properties:
server.port=8888
spring.cloud.config.server.git.uri=
management.security.enabled=假
网络模块的bootstrap.properties
spring.application.name=测试
spring.cloud.config.uri=http://localhost:8888
management.security.enabled=假
spring.profiles.active=默认,产品
Maven 依赖项(云配置客户端):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>1.4.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
<version>1.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.4.4.RELEASE</version>
</dependency>
请帮助我理解我如何 read/refresh 跨多个模块(如通用、应用程序或 Web)的属性,这些模块将部署在单个 instance/client。
由于您的 common
和 app
模块不是应用程序,它们不会启动,因此不会读取您的 bootstrap.properties 文件。
看看type-safe configuration properties and third party configuration。
您的 common
和 app
模块可以提供多个 类 及其属性。
在 web
模块的 Java 配置中,您可以设置 bootstrap.properties
and/or application.properties
文件中的值与配置 类.
由于 @ConfigurationProperties
注释,Spring Boot 将创建这些配置的常规 bean 类。这样你就可以像任何其他 bean 一样注入你的配置。
希望对您有所帮助! :)