我有rest crud服务,它将帮助我发布、获取请求并接收来自server的请求,在我的application.properties中我使用类似的数据:
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
这是我的POM:
<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项目运行这个项目时,我总是会得到以下错误:
引起: org.springframework.beans.factory.BeanCreationException:无法自动字段:私有org.springframework.boot.autoconfigure.web.HttpMessageConverters org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.messageConverters;嵌套异常是
以及:
类路径资源中定义了名称‘org/springframework/boot/autoconfigure/web/JacksonHttpMessageConvertersConfiguration$MappingJackson2HttpMessageConverterConfiguration.class:’,org/springframework/boot/autoconfigure/data/rest/SpringBootRepositoryRestMvcConfiguration.class:不满意的依赖关系通过构造函数参数表示,其索引为0,类型为com.fasterxml.jackson.databind.ObjectMapper:创建类路径资源中定义的名为“objectMapper”的bean时出错,org/springframework/boot/autoconfigure/data/rest/SpringBootRepositoryRestMvcConfiguration.class: Bean通过工厂方法实例化失败;嵌套异常是org.springframework.beans.BeanInstantiationException:未能实例化com.fasterxml.jackson.databind.ObjectMapper:工厂方法'objectMapper‘抛出的异常;嵌套异常是org.springframework.beans.factory.BeanCreationException:错误创建类路径中定义的配置名为org/springframework/boot/autoconfigure/data/rest/SpringBootRepositoryRestMvcConfiguration.class: bean的类路径资源通过工厂方法实例化失败;嵌套异常是org.springframework.beans.BeanInstantiationException:无法实例化org.springframework.data.rest.core.config.RepositoryRestConfiguration:工厂方法‘配置’抛出的异常;嵌套异常是org.springframework.beans.factory.BeanCreationException:错误,通过工厂方法创建名为“resourceMappings”的类路径资源org/springframework/boot/autoconfigure/data/rest/SpringBootRepositoryRestMvcConfiguration.class: bean实例化失败;嵌套异常是
我应该在我的pom或属性文件中更改什么来使我的程序工作?
发布于 2018-12-13 11:09:14
不建议使用Server依赖项,请使用以下方法与Server进行交互
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.1.0.jre8</version>
</dependency>
请按照链接获取更多信息。
发布于 2018-01-30 13:26:36
因为它是一个REST应用程序,所以需要在spring-boot-starter-web
中添加pom.xml
依赖项。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</dependency>
还在配置中添加连接属性(默认为application.properties
):
spring.datasource.url=jdbc:sqlserver://localhost;databaseName=springbootdb
spring.datasource.username=sa
spring.datasource.password=replace_value
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.show-sql=true
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
spring.jpa.hibernate.ddl-auto = create-drop
试一试,看看是否可以构建/运行该项目。
发布于 2021-04-08 19:03:09
将url参数更改为:
spring.datasource.url=jdbc:sqlserver://localhost:1433;databaseName=test1
端口号前面必须加上冒号(“:”),而不是斜杠(“/”)。
https://stackoverflow.com/questions/48522338
复制相似问题