Nacosサーバー設定の基本と DataBase接続の要点

サーバー設定

Spring Bootアプリケーションのサーバー設定は、アプリケーションの動作特性を定義する重要な部分です。

ポート設定

port: 8080

コンテキストパス

servlet:
  context-path: /myapp

Tomcat設定

Spring BootではTomcatがデフォルトのサーブレットコンテナとして使用されます。

# 最大接続数
max-connections: 10000

# 最大スレッド数
max-threads: 200

# 最小空きスレッド数
min-spare-threads: 10

# 待ち行列の最大長さ
accept-count: 100

# 接続タイムアウト(ミリ秒)
connection-timeout: 20000

# HTTPヘッダーサイズ制限
max-http-header-size: 8KB

# リクエスト内容の最大受信サイズ
max-swallow-size: 2MB

# URIエンコーディング
uri-encoding: UTF-8

max-connections と max-threads の違い

max-connectionsはサーバーが保持できる最大接続数を定義します。
max-threadsはサーバーが処理可能な最大スレッド数を定義します。

アプリケーション設定

server:
  # サーバー停止時の動作
  shutdown: graceful
  tomcat:
    mbeanregistry:
      enabled: true

データベース接続設定

Spring Bootのデータソース設定は、アプリケーションとデータベース間の接続を管理します。

Druidデータソース設定例

spring:
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    username: ${global.database.zoemdb.username}
    password: ${global.database.zoemdb.password}
    driver-class-name: ${global.database.zoemdb.driverClassName}
    url: ${global.database.zoemdb.url}
    druid:
      filter:
        wall:
          enabled: false
        config:
          enabled: true
      connect-properties:
        config.decrypt: true
        config.decrypt.key: ${global.database.zoemdb.decryptKey}
      max-active: ${global.database.pool.default.max-active:50}
      max-wait: ${global.database.pool.default.max-wait:5000}
      min-idle: ${global.database.pool.default.min-idel:1}
      min-evictable-idle-time-millis: ${global.database.pool.default.min-evictable-idle-time-millis:300000}
      remove-abandoned: ${global.database.pool.default.remove-abandoned:false}
      remove-abandoned-timeout-millis: ${global.database.pool.default.remove-abandoned-timeout-millis:80000}
      keep-alive: ${global.database.pool.default.keep-alive:true}
      pool-prepared-statements: ${global.database.pool.default.pool-prepared-statements}

タグ: Nacos Spring Boot サーバー設定 データベース接続 Druid

7月2日 22:39 投稿