首页 文章

在Spring Boot CLI中使用H2时未解决的依赖关系

提问于
浏览
0

我正在尝试使用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(不是 Cloud 版本)的更多信息 . 我会非常感谢你的帮助 .

2 回答

  • 0

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

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

  • 0

    不确定,但也许你的类必须被标记为Spring托管类,即将 @Repository@Component (无关紧要)添加到 ContactRepository 类 .

相关问题