簡體   English   中英

Spring Boot - Web 應用程序無法停止 MVStore 編寫器線程

[英]Spring Boot - Web app is unable to stop MVStore writer thread

我在 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');

這是定義@Table("Users")User實體

@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 */
}

這些是application.properties中的 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

感謝您的幫助

您正在組合DB_CLOSE_DELAY=-1 ,它告訴數據庫不要自動關閉,以及DB_CLOSE_ON_EXIT=TRUE 如果您希望使用 H2 持久化數據庫,請將其更改為DB_CLOSE_ON_EXIT=FALSE

就我而言:

配置文件,application.properties,這個配置:

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

不正確,控制台沒有顯示具體錯誤。😱

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM