-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAzureKeyVaultNativeApplication.java
39 lines (33 loc) · 1.56 KB
/
AzureKeyVaultNativeApplication.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.example.azure_key_vault_native;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.security.keyvault.secrets.SecretClient;
import com.azure.security.keyvault.secrets.SecretClientBuilder;
import com.azure.spring.cloud.autoconfigure.implementation.context.properties.AzureGlobalProperties;
import com.azure.spring.cloud.core.customizer.AzureServiceClientBuilderCustomizer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class AzureKeyVaultNativeApplication {
public static void main(String[] args) {
SpringApplication.run(AzureKeyVaultNativeApplication.class, args);
}
@Bean
public AzureGlobalProperties azureGlobalProperties() {
return new AzureGlobalProperties();
}
@Bean
public AzureServiceClientBuilderCustomizer<SecretClientBuilder> secretClientBuilderCustomizer() {
return builder -> builder.credential(new DefaultAzureCredentialBuilder().build());
}
@Bean
public ApplicationListener<ApplicationStartedEvent> applicationInitializers(SecretClient secretClient) {
return event -> {
System.out.println("Azure Key Vault Native Application Started");
String password = secretClient.getSecret("some-secret").getValue();
System.out.println(password);
};
}
}