本文介绍了Spring:通过Spring Boot服务连接Sql Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有rest crud服务,这将帮助我在我的application.properties内部使用sql server发布和获取请求并接收respopnses.我使用类似的数据:

I have rest crud service which will help me make post and get requests and receive respopnses from sql server , inside my application.properties i use similar data:

server.port=9004
spring.datasource.url=jdbc:sqlserver://localhost/1433;databaseName=test1
spring.datasource.username=sa
spring.datasource.password=*****
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.show-sql=true
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2014Dialect
spring.jpa.hibernate.ddl-auto =ddl-auto

这是我的宝物:

<maven.compiler.source>1.8</maven.compiler.source>
  <maven.compiler.target>1.8</maven.compiler.target>
</properties>

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.6.RELEASE</version>
    </parent>
 <dependencies>
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>sqljdbc4</artifactId>
            <version>4.0</version>
        </dependency>
        <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
      </dependency>

        </dependencies>

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

当我将其作为Java项目运行时,总是会收到此错误:

when i run this as a java project i alway got this error:

和:

我应该在pom或属性文件中进行哪些更改才能使程序正常工作?

what should i change inside my pom or properties file to make my program work?

推荐答案

不建议使用SQL Server依赖项,请使用以下命令与SQL Server进行交互

SQL Server dependency is deprecated, use following to interact with SQL Server

<dependency>
    <groupId>com.microsoft.sqlserver</groupId>
    <artifactId>mssql-jdbc</artifactId>
    <version>6.1.0.jre8</version>
</dependency>

点击链接以获取更多信息

follow links for more information

为Microsoft SQL Server配置Spring Boot

开放源代码的Microsoft JDBC驱动程序和Maven支持

这篇关于Spring:通过Spring Boot服务连接Sql Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 06:42
查看更多