We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
開発環境において、複数アプリケーションがH2DBを共有して利用する方法がアプリケーション開発手順に明記されていない追加する。
具体的な変更としては以下の通りである。
H2ServerLauncher.java(H2DBをサーバーモードで立ち上げるクラス)
@Component @Profile("local") public class H2ServerLauncher { private Server tcpServer; /** * h2サーバをサーバーモードで起動します。 */ @PostConstruct public void start() { try { this.tcpServer = Server.createTcpServer("-tcpPort", "9092", "-tcpAllowOthers", "-ifNotExists").start(); } catch (SQLException e) { System.out.println("H2 server is already started."); } } /** * h2サーバを停止します。 */ @PreDestroy public void stop() { if (this.tcpServer != null) { this.tcpServer.stop(); } } }
Configurationアノテーションのついているクラス
@Configuration public class DresscaWebConfig { @Autowired(required = false) public H2ServerLauncher h2ServerLauncher; }
プロパティファイル
spring.datasource.hikari.jdbc-url=jdbc:h2:tcp://localhost:9092/mem:./data; spring.sql.init.mode=always
アプリケーション開発手順のJava編にて、開発環境において複数アプリケーションが同じH2DBを参照する方法が追加されている。
The text was updated successfully, but these errors were encountered:
@Component を付与し、コンストラクタ内にサーバーを起動する処理を含めることで、DIコンテナ内にインスタンス化される際に、サーバーモードで起動される。 そのため、H2ServerLauncherを@Configurationアノテーションのついているクラス内でAutowiredする必要はない。
@Component
@Configuration
Sorry, something went wrong.
package com.dressca.web.admin.config; import org.h2.tools.Server; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Component; import com.dressca.systemcommon.constant.SystemPropertyConstants; import jakarta.annotation.PreDestroy; import java.sql.SQLException; /** * 開発環境で H2 Database をサーバーモードで立ち上げるためのクラスです。 */ @Component @Profile("local") public class H2ServerLauncher { private Server tcpServer; private final Logger apLog = LoggerFactory.getLogger(SystemPropertyConstants.APPLICATION_LOG_LOGGER); /** * {@link H2ServerLauncher} クラスのインスタンスを初期化し、 H2 Database をサーバーモードで起動します。 */ public H2ServerLauncher() { try { this.tcpServer = Server.createTcpServer("-tcpPort", "9092", "-tcpAllowOthers", "-ifNotExists").start(); } catch (SQLException e) { apLog.info("H2 Database は既にサーバーモードで起動しています。"); } } /** * インスタンスを破棄する際に H2 Database を停止します。 */ @PreDestroy public void stop() { if (this.tcpServer != null) { this.tcpServer.stop(); } } }
kenjiyoshid-a
Successfully merging a pull request may close this issue.
概要
開発環境において、複数アプリケーションがH2DBを共有して利用する方法がアプリケーション開発手順に明記されていない追加する。
詳細 / 機能詳細(オプション)
具体的な変更としては以下の通りである。
H2ServerLauncher.java(H2DBをサーバーモードで立ち上げるクラス)
Configurationアノテーションのついているクラス
プロパティファイル
完了条件
アプリケーション開発手順のJava編にて、開発環境において複数アプリケーションが同じH2DBを参照する方法が追加されている。
The text was updated successfully, but these errors were encountered: