Skip to content

Commit

Permalink
h2サーバー起動用のクラスをインフラから削除し、adminとconsumerに新規追加
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjiyoshid-a committed Nov 8, 2024
1 parent f5749a3 commit 00f9057
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 4 deletions.
1 change: 1 addition & 0 deletions samples/web-csr/dressca-backend/web-admin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies {
implementation supportDependencies.springdoc_openapi_starter_webmvc_ui
implementation supportDependencies.commons_lang3
implementation supportDependencies.spring_boot_security_starter
implementation supportDependencies.h2database

implementation project(':web')
implementation project(':application-core')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import com.dressca.infrastructure.config.H2ServerConfig;

/**
* Dressca Web用の設定クラス。
Expand All @@ -12,5 +11,4 @@ public class DresscaWebConfig {

@Autowired(required = false)
public H2ServerConfig h2ServerConfig;

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dressca.infrastructure.config;
package com.dressca.web.admin.config;

import org.h2.tools.Server;
import org.springframework.context.annotation.Profile;
Expand Down
1 change: 1 addition & 0 deletions samples/web-csr/dressca-backend/web-consumer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies {
implementation supportDependencies.springdoc_openapi_starter_webmvc_ui
implementation supportDependencies.commons_lang3
implementation supportDependencies.spring_boot_security_starter
implementation supportDependencies.h2database

implementation project(':web')
implementation project(':application-core')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.dressca.web.consumer.config;

import com.dressca.infrastructure.config.H2ServerConfig;
import com.dressca.web.consumer.filter.BuyerIdFilter;
import com.dressca.web.consumer.security.CookieSettings;
import jakarta.servlet.Filter;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.dressca.web.consumer.config;

import org.h2.tools.Server;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import java.sql.SQLException;

/**
* 開発環境でh2データベースを立ち上げるためのクラスです。
*/
@Component
@Profile("local")
public class H2ServerConfig {

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();
}
}
}

0 comments on commit 00f9057

Please sign in to comment.