简体   繁体   English

spring-boot-starter-data-jpa依赖错误

[英]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.

相关问题 Java:依赖项目中的spring-boot-starter-data-jpa依赖 - Java : spring-boot-starter-data-jpa dependency in a dependent project 将“spring-boot-starter-data-jpa”依赖项添加到Spring项目时出错 - Error when adding “spring-boot-starter-data-jpa” dependency to Spring project 未找到依赖项 &#39;org.springframework.boot:spring-boot-starter-data-jpa:2.5.3&#39; - Dependency 'org.springframework.boot:spring-boot-starter-data-jpa:2.5.3' not found Spring 引导不添加 spring-boot-starter-data-jpa - Spring boot not adding spring-boot-starter-data-jpa 有什么办法可以不在 spring-boot-starter-data-jpa 依赖中使用 exclude 并保持相同的存储吗? - Is there any way to not to use exclude in the spring-boot-starter-data-jpa dependency and maintain the same storage? 有关Spring-boot-starter-data-jpa的问题 - A question about the Spring-boot-starter-data-jpa spring-boot-starter-data-jpa:自动重新连接 - spring-boot-starter-data-jpa : Auto Reconnect 排除 JPA Spring boot - org.springframework.boot:spring-boot-starter-data-jpa&#39; 启动时导致 CRUDRepository 错误 - Exclude JPA Spring boot - org.springframework.boot:spring-boot-starter-data-jpa' causes error in CRUDRepository when starting 使用 spring-boot-starter-data-jpa 时 Hibernate-core 错误 - Hibernate-core error when using spring-boot-starter-data-jpa H2 数据库是用 spring-boot-starter-data-jpa 创建的,但不是用 spring-boot-starter-data-jdbc 创建的 - H2 Database created with spring-boot-starter-data-jpa but not with spring-boot-starter-data-jdbc
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM