Last active
October 9, 2024 08:08
-
-
Save unclebean/092b58ae18eacf5e84a1c504c541ab3a to your computer and use it in GitHub Desktop.
Azure config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Spring Cloud Azure Starter --> | |
<dependency> | |
<groupId>com.azure.spring</groupId> | |
<artifactId>spring-cloud-azure-starter</artifactId> | |
</dependency> | |
<!-- Azure Blob Storage --> | |
<dependency> | |
<groupId>com.azure.spring</groupId> | |
<artifactId>spring-cloud-azure-starter-storage-blob</artifactId> | |
</dependency> | |
<!-- Azure Cognitive Search --> | |
<dependency> | |
<groupId>com.azure.spring</groupId> | |
<artifactId>spring-cloud-azure-starter-cognitive-search</artifactId> | |
</dependency> | |
<!-- Azure PostgreSQL (if needed) --> | |
<dependency> | |
<groupId>com.azure.spring</groupId> | |
<artifactId>spring-cloud-azure-starter-data-jdbc</artifactId> | |
</dependency> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
spring: | |
cloud: | |
azure: | |
storage: | |
account-name: your-storage-account-name | |
account-key: your-storage-account-key # If not using managed identity | |
endpoint: https://your-storage-account-name.blob.core.windows.net | |
spring: | |
cloud: | |
azure: | |
cognitive-search: | |
service-name: your-cognitive-search-service-name | |
api-key: your-cognitive-search-api-key # If not using managed identity | |
endpoint: https://your-cognitive-search-service-name.search.windows.net | |
spring: | |
datasource: | |
url: jdbc:postgresql://your-postgres-server.postgres.database.azure.com:5432/your-database-name | |
username: your-database-username@your-postgres-server | |
password: your-database-password | |
driver-class-name: org.postgresql.Driver | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Bean | |
public BlobServiceClient blobServiceClient() { | |
// Build a credential using User-Assigned Managed Identity | |
ManagedIdentityCredential managedIdentityCredential = new ManagedIdentityCredentialBuilder() | |
.clientId(clientId) | |
.build(); | |
// Build the BlobServiceClient using the Managed Identity Credential | |
return new BlobServiceClientBuilder() | |
.endpoint(String.format("https://%s.blob.core.windows.net", accountName)) | |
.credential(managedIdentityCredential) | |
.buildClient(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Bean | |
public SearchClient searchClient() { | |
// Create a credential using the User-Assigned Managed Identity | |
ManagedIdentityCredential managedIdentityCredential = new ManagedIdentityCredentialBuilder() | |
.clientId(clientId) | |
.build(); | |
// Build the SearchClient using Managed Identity Credential | |
return new SearchClientBuilder() | |
.credential(managedIdentityCredential) | |
.endpoint(searchEndpoint) | |
.indexName(indexName) | |
.buildClient(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
spring: | |
cloud: | |
azure: | |
identity: | |
client-id: your-managed-identity-client-id # Only needed for User-Assigned Managed Identity |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Spring Data JPA --> | |
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-data-jpa</artifactId> | |
</dependency> | |
<!-- JDBI for SQL queries --> | |
<dependency> | |
<groupId>org.jdbi</groupId> | |
<artifactId>jdbi3-core</artifactId> | |
</dependency> | |
<dependency> | |
<groupId>org.jdbi</groupId> | |
<artifactId>jdbi3-sqlobject</artifactId> | |
</dependency> | |
<!-- PostgreSQL driver --> | |
<dependency> | |
<groupId>org.postgresql</groupId> | |
<artifactId>postgresql</artifactId> | |
</dependency> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
spring: | |
datasource: | |
url: jdbc:postgresql://your-postgres-server.postgres.database.azure.com:5432/your-database-name | |
username: your-database-username@your-postgres-server | |
password: your-database-password | |
driver-class-name: org.postgresql.Driver | |
hikari: | |
maximum-pool-size: 10 | |
jpa: | |
hibernate: | |
ddl-auto: update # Can be 'none', 'update', 'validate', etc. | |
show-sql: true | |
properties: | |
hibernate: | |
dialect: org.hibernate.dialect.PostgreSQLDialect |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.jdbi.v3.core.Jdbi; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import javax.sql.DataSource; | |
@Configuration | |
public class JdbiConfig { | |
@Bean | |
public Jdbi jdbi(DataSource dataSource) { | |
return Jdbi.create(dataSource); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
java -jar app.jar --spring.profiles.active=dev