首页 > 解决方案 > 将 Spring Boot 连接到 SQL Server Express

问题描述

我尝试将我的 gradle Spring Boot 应用程序连接到正在运行的 SQL Server Express 安装。

我的配置是

    spring.datasource.url=jdbc:sqlserver://localhost;InstanceName=SQLEXPRESS;databaseName=testDB;integratedsecurity=true
    spring.datasource.username=SpringBootUser
    spring.datasource.password=testPassword123
    spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
    spring.jpa.show-sql=true
    spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServerDialect
    spring.jpa.hibernate.ddl-auto = validate

build.grade 具有这些依赖项:

plugins {
    id 'org.springframework.boot' version '2.2.6.RELEASE'
    id 'io.spring.dependency-management' version '1.0.9.RELEASE'
    id 'java'
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-data-rest'
    implementation 'org.springframework.boot:spring-boot-starter-hateoas'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compileOnly 'org.projectlombok:lombok'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    runtimeOnly 'com.microsoft.sqlserver:mssql-jdbc'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
}

但我得到的只是这些信息:

原因:org.hibernate.service.spi.ServiceException:无法创建请求的服务 [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]

原因:org.hibernate.HibernateException:当未设置“hibernate.dialect”时,对 DialectResolutionInfo 的访问不能为空

标签: javaspring-bootspring-data-jpasql-server-express

解决方案


确保你的类路径中有一个 application.properties。您的应用程序似乎无法加载您的配置文件。


推荐阅读