taa*_*thy 16 java sql-server ssl pkix spring-boot
我在本地计算机上安装 SQL Server 并将其嵌入到我的 Spring Boot 应用程序中。启动Tomcat后出现以下错误:
'PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target'. ClientConnectionId:85411829-6853-4fdb-9373-b4c93e1d5e8f
我知道这个错误有详细记录。我遵循了许多指南并阅读了很多相关内容,但我发现的所有建议都没有解决我的问题。
我做了什么:
从网站下载随机 SSL 证书并将其添加到 Java 目录中的 cacert 文件中(在此处进行描述)。
为 SQL Server 配置 Spring Boot(此处描述)
为 SQL Server 配置 SSL 加密(此处描述)
这些建议都没有解决该错误。我唯一意识到的是,如果我设置spring.jpa.hibernate.ddl-auto
程序application.properties
会none
显示错误消息,但它不会中止运行。
application.properties 如下所示:
spring.datasource.url=jdbc:sqlserver://localhost;databaseName=Car
spring.datasource.username=admin
spring.datasource.password=password123
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.hibernate.ddl-auto=none
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
server.port=8443
server.ssl.key-alias=selfsigned_localhost_sslserver
server.ssl.key-password=changeit
server.ssl.key-store=classpath:ssl-server.jks
server.ssl.key-store-provider=SUN
server.ssl.key-store-type=JKS
Run Code Online (Sandbox Code Playgroud)
我的依赖项:
<dependencies>
<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>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
在 SQL Server 中,我创建一个包含表和数据的数据库。
你们中有人对如何修复此错误有进一步的建议吗?
M. *_*mer 43
从您使用驱动程序 10.2.X 的评论看来
事实证明,从 2.7.0 开始,使用 SQL Server 的
JDBC驱动程序 10.2
,而不是2.6.x 的9.4.1.jre8
所以你有两个对我有用的解决方案之一:
1.使用旧版本的mssql-jdbc驱动程序
<properties>
<mssql-jdbc.version>9.4.1.jre8</mssql-jdbc.version>
</properties>
Run Code Online (Sandbox Code Playgroud)
2. 或者要求驱动程序只信任 Sql 服务器证书,
您可以通过将其添加到连接字符串来做到这一点:
jdbc:sqlserver://hOSt:pORt;databaseName=dbName;encrypt=true;trustServerCertificate=true
Run Code Online (Sandbox Code Playgroud)
小智 5
我对现有服务器有同样的问题,它有帮助:
有帮助的通知:加密 = true; trustServerCertificate = true
另请记住,当您在 java 中创建实体时,请确保在数据库中创建了相同的实体。
# Microsoft SQL Server config
spring.datasource.url=jdbc:sqlserver://serverNameOrAdress:1443;databaseName=****;encrypt=true;trustServerCertificate=true
spring.jpa.database-platform=org.hibernate.dialect.SQLServerDialect
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.username=***
spring.datasource.password=***
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
22960 次 |
最近记录: |