Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion mi-sql-public-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,32 @@
<java.version>17</java.version>
</properties>

<!-- Add Spring Cloud Azure BOM -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>spring-cloud-azure-dependencies</artifactId>
<version>5.22.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>10.2.0.jre11</version>
</dependency>


<!-- Add Spring Cloud Azure starter for managed identity support -->
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>spring-cloud-azure-starter</artifactId>
</dependency>

</dependencies>

<build>
Expand Down
9 changes: 8 additions & 1 deletion mi-sql-public-demo/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
AZURE_SQLDB_CONNECTIONSTRING=jdbc:sqlserver://${AZ_DATABASE_SERVER_NAME}.database.windows.net:1433;database=demo;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;
AZURE_CLIENT_ID=<your managed identity client id>
AZURE_CLIENT_ID=<your managed identity client id>

# Enable Azure managed identity for Spring Cloud Azure
spring.cloud.azure.credential.managed-identity-enabled=true
spring.cloud.azure.credential.client-id=${AZURE_CLIENT_ID}

# Add datasource URL for Azure SQL using Managed Identity authentication
spring.datasource.url=jdbc:sqlserver://${AZ_DATABASE_SERVER_NAME}.database.windows.net:1433;database=demo;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;authentication=ActiveDirectoryMSI