Connect to MSSQL from Spring boot application using windows authentication

我是研究僧i 提交于 2021-02-19 02:22:28

问题


I am currently using the below properties to connect to a remotely Mssql server from Java spring boot application:

spring.datasource.url=jdbc:sqlserver://ip\\domain;databaseName=name
spring.datasource.username=abc
spring.datasource.password=def
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver

The application runs from both windows and unix servers. I need now to start using the windows authentication instead of the db credentials. This is already configured and supported from MSSQL side. From Java spring boot this is not working. I tried to add to the url: integratedSecurity=true it said it cannot find a dll. I added sqljdbc_auth.dll to java jre bin folder and it didnt work.


回答1:


Try use jtds driver, and in apllication properties use:

    app.datasource.youraplication.jdbcUrl=jdbc:jtds:sqlserver://yourBdHost/yourSchemaBd;domain=yourDomain



回答2:


I'm working on MS SQL Server 2016, Hibernate 5.3.7.Final and Spring bot 2.2.0. For me, adding this line to properties worked: (without jtds!)

spring.datasource.url=jdbc:servername;databasename=your_db_name;integratedSecurity=true

You may also need these properties:

spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect

And if you encounter a problem with "no sqljdbc_auth in java.library.path". You may refer to this answer no sqljdbc_auth.




回答3:


Download the drivers from: https://docs.microsoft.com/en-us/sql/connect/jdbc/download-microsoft-jdbc-driver-for-sql-server?view=sql-server-2017

Add the jar to your project Right Click on project - > Build Path -> Configure Build Path - > Libraries -> Add External JARs

Add "integratedSecurity=true" to your connection string and remove username and password



来源:https://stackoverflow.com/questions/52813704/connect-to-mssql-from-spring-boot-application-using-windows-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!