[英]spring-boot-starter-data-jpa dependency error
I am using new version of Spring boot - 1.5.7. 我正在使用新版本的Spring Boot-1.5.7。 But , when I create new spring starter project with jpa dependency, I got strange error: 但是,当我创建具有jpa依赖关系的新spring starter项目时,出现了奇怪的错误:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected at least 1 bean which qualifies as autowire candidate. 由以下原因引起:org.springframework.beans.factory.NoSuchBeanDefinitionException:没有类型为'javax.sql.DataSource'的合格Bean:预期至少有1个有资格作为自动装配候选的Bean。 Dependency annotations: {} 依赖注释:{}
Could anybody help me: Here is my pom.xml
谁能帮我:这是我的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo-11</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo-11</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
You need to include a database in your dependencies. 您需要在依赖项中包括一个数据库。 If a database was found, spring boot auto-configures your datasource for you. 如果找到数据库,Spring Boot会自动为您配置数据源。
See this example, which includes a h2database. 请参见此示例,其中包括h2database。
https://spring.io/guides/gs/accessing-data-jpa/ https://spring.io/guides/gs/accessing-data-jpa/
You need to put your database related info in the application.properties file 您需要将与数据库相关的信息放入application.properties文件中
spring.jpa.hibernate.ddl-auto=create
spring.datasource.url=jdbc:mysql://localhost:3306/db_example
spring.datasource.username=springuser
spring.datasource.password=ThePassword
And you need to put the database dependency in your pom.xml 并且您需要将数据库依赖项放在pom.xml中
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
this is how it's listed in the official site for mysql, you can try with your database of choice. 这是mysql官方网站上列出的方式,您可以尝试使用自己选择的数据库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.