美文网首页
SpringBoot未添加内置数据库启动报错

SpringBoot未添加内置数据库启动报错

作者: 路上捡只猫 | 来源:发表于2019-01-16 19:38 被阅读0次

    在配置

    <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-jpa</artifactId>
            </dependency>
            <dependency>
                    <groupId>mysql</groupId>
                    <artifactId>mysql-connector-java</artifactId>
                    </dependency>
                
    

    出现

    Description:
    
    Parameter 0 of constructor in org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration required a bean of type 'javax.sql.DataSource' that could not be found.
        - Bean method 'dataSource' not loaded because @ConditionalOnClass did not find required class 'org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType'
        - Bean method 'dataSource' not loaded because @ConditionalOnClass did not find required class 'org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType'
    
    
    Action:
    
    Consider revisiting the conditions above or defining a bean of type 'javax.sql.DataSource' in your configuration.
    

    是因为在项目中没有引入数据源,但是又引入了JPA,所以引起报错。解决方式就是内嵌一个runtime数据库。本文添加的是h2数据库

    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>
    </dependency>
    

    问题解决。

    相关文章

      网友评论

          本文标题:SpringBoot未添加内置数据库启动报错

          本文链接:https://www.haomeiwen.com/subject/spfvdqtx.html