configmap.yaml 3.62 KB
apiVersion: v1
kind: ConfigMap
metadata:
  name: product-service-config
  namespace: ecommerce
  labels:
    app: product-service
data:
  application.yml: |
    server:
      port: 8080
      servlet:
        context-path: /api/products
    
    spring:
      application:
        name: product-service
      profiles:
        active: production
      
      # PostgreSQL 数据库配置
      datasource:
        # ========== 修改点1:修复数据库主机名 ==========
        url: jdbc:postgresql://postgresql:5432/ecommerce  # 修改:postgresql-service → postgresql
        username: admin
        password: ${POSTGRES_PASSWORD}
        driver-class-name: org.postgresql.Driver
        hikari:
          maximum-pool-size: 10
          minimum-idle: 2
          connection-timeout: 30000
          idle-timeout: 600000
          max-lifetime: 1800000
      
      # JPA 配置
      jpa:
        hibernate:
          ddl-auto: update
          naming:
            physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
        # ========== 修改点2:临时开启SQL日志便于调试 ==========
        show-sql: true  # 修改:false → true (调试完成后可改回false)
        properties:
          hibernate:
            dialect: org.hibernate.dialect.PostgreSQLDialect
            format_sql: true
            jdbc:
              batch_size: 20
              order_inserts: true
              order_updates: true
      
      # MongoDB 配置
      data:
        mongodb:
          # ========== 修改点3:修复MongoDB主机名和数据库名 ==========
          uri: mongodb://admin:${MONGO_PASSWORD}@mongodb:27017/product_db?authSource=admin  # 修改:ecommerce → product_db
          database: product_db  # 修改:ecommerce → product_db
          auto-index-creation: true
      
      # Redis 配置
      redis:
        # ========== 修改点4:修复Redis主机名 ==========
        host: redis  # 修改:redis-service → redis
        port: 6379
        password: ${REDIS_PASSWORD}
        timeout: 2000
        lettuce:
          pool:
            max-active: 10
            max-idle: 5
            min-idle: 2
            max-wait: 1000
      
      # 缓存配置
      cache:
        type: redis
        redis:
          time-to-live: 3600000
          cache-null-values: false
    
    # 禁用 Eureka 服务发现
    eureka:
      client:
        enabled: false
        register-with-eureka: false
        fetch-registry: false
      instance:
        enabled: false
    
    # Elasticsearch 配置
    elasticsearch:
      # ========== 修改点5:修复Elasticsearch主机名 ==========
      host: elasticsearch  # 修改:elasticsearch-service → elasticsearch
      port: 9200
    
    # 功能标志配置
    feature:
      flags:
        cache-enabled: true
        search-enabled: true
    
    # 日志配置
    logging:
      level:
        com.ecommerce.productservice: DEBUG
        org.springframework.data.mongodb.core: WARN
        # ========== 修改点6:临时调整Hibernate日志级别便于调试 ==========
        org.hibernate.SQL: DEBUG  # 修改:WARN → DEBUG (调试数据库问题)
        org.hibernate.type.descriptor.sql.BasicBinder: DEBUG  # 修改:WARN → DEBUG
        # ========== 新增:添加数据库连接相关日志 ==========
        org.hibernate.engine.jdbc.connections: DEBUG
        com.zaxxer.hikari: DEBUG
    
    # Actuator 配置
    management:
      endpoints:
        web:
          exposure:
            include: health,info,metrics,prometheus
      endpoint:
        health:
          show-details: always
          probes:
            enabled: true