Home > Back-end >  Spring Boot connection to SQL Server in Windows Authentication mode
Spring Boot connection to SQL Server in Windows Authentication mode

Time:04-18

I am new in Spring Boot, I am trying to connect to SQL Server in Windows Authentication mode and here is my database configuration:

database.name= DatabaseName spring.datasource.url=jdbc:sqlserver://1.2.3.4:11111;DatabaseName=${database.name};integratedSecurity = true;
 spring.datasource.username=user
 spring.datasource.password=passw
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver 

and I got these errors:

Negative matches:


AVSSimulatorServerApplication:
      Did not match:
         - @ConditionalOnProperty (spring.application.name=avs-simulator-service) found different value in property 'spring.application.name' (OnPropertyCondition)

ActiveMQAutoConfiguration:
      Did not match:
         - @ConditionalOnClass did not find required classes 'javax.jms.ConnectionFactory', 'org.apache.activemq.ActiveMQConnectionFactory' (OnClassCondition)

   AopAutoConfiguration.JdkDynamicAutoProxyConfiguration:
      Did not match:
         - @ConditionalOnProperty (spring.aop.proxy-target-class=false) found different value in property 'proxy-target-class' (OnPropertyCondition)

   ArtemisAutoConfiguration:
      Did not match:
         - @ConditionalOnClass did not find required classes 'javax.jms.ConnectionFactory', 'org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory' (OnClassCondition)

   AsyncCustomAutoConfiguration:
      Did not match:
         - @ConditionalOnBean (types: org.springframework.scheduling.annotation.AsyncConfigurer; SearchStrategy: all) did not find any beans (OnBeanCondition)
      Matched:
         - @ConditionalOnProperty (spring.sleuth.async.enabled) matched (OnPropertyCondition)
.......

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'user'. ClientConnectionId:ce912574-1f20-4843-9b43-01820e67cf54

Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'user'. ClientConnectionId:ce912574-1f20-4843-9b43-01820e67cf54

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.util.HashMap]: 

................

Do anybody know what should I do in this situation? I read a lot of questions in stack overflow on similar topic but did not find correct answer for me.

CodePudding user response:

I found the solution and it was only to use

integratedSecurity = false;

instead of

integratedSecurity = true;

so in this case connection string will be:

database.name= DatabaseName spring.datasource.url=jdbc:sqlserver://1.2.3.4:11111;DatabaseName=${database.name};integratedSecurity = false;.

Why to use integratedSecurity = false? The reason is here:

"Integrated Security When false, User ID and Password are specified in the connection. When true, the current Windows account credentials are used for authentication."

  • Related