无法配置 DataSource: 在使用 ActiveDirectoryMSI、MSSQL 和 SQLServerDataSource 时'url'



我有一个使用MSSQL的Springboot应用程序,我正在Azure上部署它。它使用ActiveDirectoryMSI进行身份验证。数据源配置类如下所示

@Configuration
@Slf4j
public class DataSourceConfig {
@Value("${sql.databaseName}")
private String sqlDbName;
@Value("${sql.serverName}")
private String sqlServer;
@Value("${sql.msiClientId}")
private String sqlIdentity;
@Bean
public void connectToDb() {
SQLServerDataSource ds = new SQLServerDataSource();
ds.setServerName(sqlServer + ".database.windows.net");
ds.setDatabaseName(sqlDbName);
ds.setMSIClientId(sqlIdentity);
ds.setAuthentication("ActiveDirectoryMSI");
try (Connection connection = ds.getConnection()) {
log.info("Connected to database using my MSI");
} catch (SQLServerException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}

这些变量的所有值都存储在KeyVault中。问题是,在构建之后,当我尝试部署应用程序时,它需要application.yml中的url,但我没有,因为所有信息都应该来自azure上的Keyvault。所以它给了我以下的错误。我不能给它一个url,因为这种MSI方式不需要url

***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class

Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

这是我的pom.xml。我没有在application.yml 中放入任何与Spring.datasource相关的内容

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>2.3.8</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>2.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-engine</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
</dependencies>

你知道我该如何纠正这个问题吗?感谢

想明白了。必须将h2依赖关系的范围从测试更改为运行时

最新更新