W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
要在應(yīng)用程序中使用這些功能,只需將其構(gòu)建為依賴于spring-cloud-vault-config
的Spring Boot應(yīng)用程序即可(例如,查看測(cè)試用例)。Maven示例配置:
示例101.1 pom.xml
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.0.RELEASE</version> <relativePath /> <!-- lookup parent from repository --> </parent> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-vault-config</artifactId> <version>{project-version}</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> <!-- repositories also needed for snapshots and milestones -->
然后,您可以創(chuàng)建一個(gè)標(biāo)準(zhǔn)的Spring Boot應(yīng)用程序,例如以下簡(jiǎn)單的HTTP服務(wù)器:
@SpringBootApplication @RestController public class Application { @RequestMapping("/") public String home() { return "Hello World!"; } public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
運(yùn)行時(shí),它將從端口8200
上的默認(rèn)本地Vault服務(wù)器獲取外部配置(如果正在運(yùn)行)。要修改啟動(dòng)行為,您可以使用bootstrap.properties
來(lái)更改Vault服務(wù)器的位置(例如application.properties
,但用于應(yīng)用程序上下文的引導(dǎo)階段),例如
示例101.2 bootstrap.yml
spring.cloud.vault: host: localhost port: 8200 scheme: https uri: https://localhost:8200 connection-timeout: 5000 read-timeout: 15000 config: order: -10
host
設(shè)置Vault主機(jī)的主機(jī)名。主機(jī)名將用于SSL證書(shū)驗(yàn)證
port
設(shè)置Vault端口
scheme
將方案設(shè)置為http
將使用純HTTP。支持的方案是http
和https
。
uri
使用URI配置Vault端點(diǎn)。優(yōu)先于主機(jī)/端口/方案配置
connection-timeout
設(shè)置連接超時(shí)(以毫秒為單位)
read-timeout
設(shè)置讀取超時(shí)(以毫秒為單位)
config.order
設(shè)置屬性來(lái)源的順序
啟用進(jìn)一步的集成需要附加的依賴關(guān)系和配置。根據(jù)您設(shè)置Vault的方式,可能需要其他配置,例如 SSL和 身份驗(yàn)證。
如果應(yīng)用程序?qū)肓?code class="literal" i="4551">spring-boot-starter-actuator項(xiàng)目,則可以通過(guò)/health
端點(diǎn)獲得保管庫(kù)服務(wù)器的狀態(tài)。
可以通過(guò)屬性management.health.vault.enabled
(默認(rèn)值為true
)啟用或禁用Vault運(yùn)行狀況指示器。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: