代码之家  ›  专栏  ›  技术社区  ›  tenticon

Spring Boot-Web应用程序无法停止MVStore writer线程

  •  0
  • tenticon  · 技术社区  · 7 年前

    我在spring boot应用程序中使用嵌入式H2数据库,但每次关机时,数据库都不会像我在中配置的那样正确关闭/删除 application.properties . 以下是关闭应用程序时出现的错误:

    2018-02-05 13:00:37.360 WARN  [localhost-startStop-2] [WebappClassLoaderBase] 
         The web application [ROOT] appears to have started a 
         thread named [MVStore background writer nio:C:/Users/user/testdb.mv.db] but has failed to stop it. 
         This is very likely to create a memory leak. Stack trace of thread:
     java.lang.Object.wait(Native Method)
     org.h2.mvstore.MVStore$BackgroundWriterThread.run(MVStore.java:2715)
    

    其效果是文件testdb。mv保留在我的用户目录中,在随后的启动中

    org.h2.jdbc.JdbcSQLException: Unique index or primary key violation: "PRIMARY KEY ON PUBLIC.USERS(ID)"; SQL statement:
    INSERT INTO Users (id,first_name,last_name) VALUES (1,'Vincent', 'Vega') [23505-196]
        at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
        at org.h2.message.DbException.get(DbException.java:179)
    

    这是 data.sql 启动时运行的脚本

    INSERT INTO Users (id,first_name,last_name) VALUES (1,'Vincent', 'Vega');
    

    这是 User 定义 @Table("Users")

    @Entity
    @Table(name="Users")
    public class User 
    {
        @Id
        @GeneratedValue
        private long id;
    
        @Column(name="first_name")
        private String firstName;
    
        @Column(name="last_name")
        private String lastName;
        /* getters and setters */
    }
    

    这些是中的h2相关配置 应用属性

    spring.jpa.generate-ddl=true
    spring.jpa.hibernate.ddl-auto=none 
    spring.jpa.database=H2
    spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
    spring.jpa.show-sql=true
    spring.datasource.driverClassName=org.h2.Driver
    spring.datasource.url=jdbc:h2:~/testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=TRUE
    spring.datasource.name=testdb
    spring.h2.console.enabled=true
    spring.h2.console.path=/h2-console
    

    谢谢你的帮助

    2 回复  |  直到 7 年前
        1
  •  1
  •   veljkost    7 年前

    您正在合并 DB_CLOSE_DELAY=-1 ,指示db不要自动关闭,以及 DB_CLOSE_ON_EXIT=TRUE . 将其更改为 DB_CLOSE_ON_EXIT=FALSE 如果希望有一个具有H2的持久化数据库。

        2
  •  0
  •   Barrrettt    5 年前

    就我而言:

    配置文件,应用程序。属性,这将配置:

    server.ssl.key-alias=***
    server.ssl.key-store-password=****
    

    错误,控制台未显示具体错误。±