H2数据库未创建或访问

时间:2019-06-27 12:52:54

标签: spring hibernate spring-boot jpa h2

我的H2数据库(最新的稳定版本)没有从我尝试过的其他方法加载或创建,请在下面显示我到目前为止所做的事情:

我的域:

@Entity
public class Categoria implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer id;
private String nome;

public Categoria() {

}

我的资源

@RestController 
@RequestMapping(value="/categorias")
public class CategoriaResource {

@RequestMapping(method=RequestMethod.GET)
public List<Categoria> listar() {

    Categoria cat1 = new Categoria(1, "Informática");
    Categoria cat2 = new Categoria(2, "Escritório");

    List<Categoria> lista = new ArrayList<>();
    lista.add(cat1);
    lista.add(cat2);


    return lista;
}

然后是我的application.properties:

spring.h2.console.enabled=true
spring.h2.console.path=/h2-console

spring.datasource.url=jdbc:h2:file:~/h2/test
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driver-class-name=org.h2.Driver

spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true

spring.jpa.hibernate.ddl-auto=update

当我尝试打开localhost:8080并输入JDBC URL:jdbc:h2:file:〜/ h2 / test时,弹出错误消息:

  

找不到数据库“ C:/ Users / XXX / h2 / test”,并且IFEXISTS = true,因此我们   无法自动创建它[90146-199] 90146/90146(帮助)

URL:jdbc:h2:file:〜/ test里面没有显示任何数据库,这是事实。

URL:jdbc:h2:test

数据库URL“ jdbc:h2:test; IFEXISTS = TRUE”中不允许隐式相对于当前工作目录的文件路径。请使用绝对路径〜/ name,。/ name或baseDir设置。 [90011-199] 90011/90011(帮助)

最后是URL:jdbc:h2:mem:test

  

找不到数据库“ mem:test”,并且IFEXISTS = true,所以我们无法   自动创建它[90146-199] 90146/90146(帮助)

我真的不知道该怎么办,到目前为止已经尝试了所有方法。 我该怎么办甚至从内存或本地访问?

预先感谢;

0 个答案:

没有答案
相关问题