【问题标题】:Unresolved dependency when using H2 in Spring Boot CLI在 Spring Boot CLI 中使用 H2 时未解决的依赖关系
【发布时间】:2018-03-11 01:14:25
【问题描述】:

我正在尝试使用 Spring Boot CLI (1.5.7) 实现一个使用 h2 数据库的小型 REST 服务。 但是解决依赖关系不起作用。我收到错误: “引起:org.springframework.beans.factory.UnsatisfiedDependencyException” ... "工厂方法 'dataSource' 抛出异常;嵌套异常是 org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: 无法确定数据库类型 NONE 的嵌入式数据库驱动程序类"

@Grab("h2")

import java.sql.ResultSet

class ContactRepository {
  @Autowired
  JdbcTemplate jdbc

  List<Contact> findAll() { ... }
}

我认为通过使用 @Grab("h2") Spring Boot 会将类/jar 添加到类路径中。我找不到很多关于 Spring Boot CLI(不是云版本)的资源。 我将非常感谢您的帮助。

【问题讨论】:

    标签: spring spring-boot command-line-interface h2


    【解决方案1】:

    添加

    <dependency>
        <groupId>org.hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
        <scope>test</scope>
    </dependency>
    

    在你的模块的 pom 中,spring boot 会自动检测类路径上的 hsqldb。

    【讨论】:

      【解决方案2】:

      不确定,但也许您的课程必须标记为 Spring 托管课程,即将 @Repository@Component(没关系)添加到您的 ContactRepository 课程。

      【讨论】:

        猜你喜欢
        • 2020-06-21
        • 2013-02-11
        • 2017-10-11
        • 1970-01-01
        • 2013-02-14
        • 2013-10-27
        • 1970-01-01
        • 2016-03-26
        • 1970-01-01
        相关资源
        最近更新 更多