欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JAVA系統(tǒng)中Spring?Boot應(yīng)用程序的配置文件application.yml使用詳解

 更新時間:2025年01月22日 11:08:52   作者:天之涯上上  
這篇文章主要介紹了JAVA系統(tǒng)中Spring?Boot應(yīng)用程序的配置文件application.yml的相關(guān)資料,application.yml是Spring?Boot應(yīng)用程序的配置文件,定義了服務(wù)器、Spring、日志、安全及其他配置屬性,確保應(yīng)用程序正確啟動和運(yùn)行,需要的朋友可以參考下

backend\src\main\resources\application.yml 是一個配置文件,用于定義 Spring Boot 應(yīng)用程序的各種配置屬性。這個文件通常包含數(shù)據(jù)庫連接、服務(wù)器設(shè)置、日志配置、安全設(shè)置以及其他應(yīng)用程序級別的配置。

文件路徑

backend\src\main\resources\application.yml

文件內(nèi)容

以下是一個典型的 application.yml 文件的示例:

server:
  port: 8080
  servlet:
    context-path: /erp

spring:
  application:
    name: mechanical-erp-backend
  datasource:
    url: jdbc:mysql://localhost:3306/mechanical_erp?useSSL=false&serverTimezone=UTC
    username: root
    password: root
    driver-class-name: com.mysql.cj.jdbc.Driver
  jpa:
    hibernate:
      ddl-auto: update
    show-sql: true
    properties:
      hibernate:
        dialect: org.hibernate.dialect.MySQL5InnoDBDialect
        format_sql: true
  security:
    user:
      name: admin
      password: admin123

logging:
  level:
    root: INFO
    com.mechanical.erp: DEBUG

management:
  endpoints:
    web:
      exposure:
        include: "*"

security:
  oauth2:
    resourceserver:
      jwt:
        issuer-uri: https://your-auth-server.com/oauth/token

# 其他自定義配置
custom:
  app:
    feature-flag:
      new-ui: true
    timeout:
      default: 30s

解釋

1. Server 配置

server:
  port: 8080
  servlet:
    context-path: /erp
  • port: 指定應(yīng)用程序監(jiān)聽的端口號。
  • context-path: 指定應(yīng)用程序的上下文路徑。

2. Spring 配置

spring:
  application:
    name: mechanical-erp-backend
  datasource:
    url: jdbc:mysql://localhost:3306/mechanical_erp?useSSL=false&serverTimezone=UTC
    username: root
    password: root
    driver-class-name: com.mysql.cj.jdbc.Driver
  jpa:
    hibernate:
      ddl-auto: update
    show-sql: true
    properties:
      hibernate:
        dialect: org.hibernate.dialect.MySQL5InnoDBDialect
        format_sql: true
  security:
    user:
      name: admin
      password: admin123
  • application.name: 指定應(yīng)用程序的名稱。
  • datasource: 數(shù)據(jù)庫連接配置,包括 URL、用戶名、密碼和驅(qū)動類名。
  • jpa:
    • hibernate.ddl-auto: 指定 Hibernate 如何自動處理數(shù)據(jù)庫模式(例如 updatecreatecreate-drop)。
    • show-sql: 是否在控制臺顯示 SQL 語句。
    • properties.hibernate.dialect: 指定使用的 Hibernate 方言。
    • properties.hibernate.format_sql: 是否格式化 SQL 語句。
  • security.user: 默認(rèn)用戶的安全配置,包括用戶名和密碼。

3. Logging 配置

logging:
  level:
    root: INFO
    com.mechanical.erp: DEBUG
  • root: 設(shè)置根日志級別為 INFO。
  • com.mechanical.erp: 設(shè)置特定包的日志級別為 DEBUG

4. Management 配置

management:
  endpoints:
    web:
      exposure:
        include: "*"
  • endpoints.web.exposure.include: 暴露所有管理端點(diǎn)。

5. Security 配置

security:
  oauth2:
    resourceserver:
      jwt:
        issuer-uri: https://your-auth-server.com/oauth/token
  • oauth2.resourceserver.jwt.issuer-uri: 指定 JWT 發(fā)行者的 URI。

6. 自定義配置

custom:
  app:
    feature-flag:
      new-ui: true
    timeout:
      default: 30s
  • custom.app.feature-flag.new-ui: 自定義功能標(biāo)志,啟用新 UI。
  • custom.app.timeout.default: 自定義默認(rèn)超時時間。

使用示例

以下是一些常見的配置項及其用途:

數(shù)據(jù)庫連接配置

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/mechanical_erp?useSSL=false&serverTimezone=UTC
    username: root
    password: root
    driver-class-name: com.mysql.cj.jdbc.Driver
  • url: 數(shù)據(jù)庫連接 URL。
  • username: 數(shù)據(jù)庫用戶名。
  • password: 數(shù)據(jù)庫密碼。
  • driver-class-name: JDBC 驅(qū)動類名。

JPA 配置

spring:
  jpa:
    hibernate:
      ddl-auto: update
    show-sql: true
    properties:
      hibernate:
        dialect: org.hibernate.dialect.MySQL5InnoDBDialect
        format_sql: true
  • ddl-auto: 控制 Hibernate 如何處理數(shù)據(jù)庫模式。
  • show-sql: 是否在控制臺顯示 SQL 語句。
  • dialect: 指定使用的 Hibernate 方言。
  • format_sql: 是否格式化 SQL 語句。

日志配置

logging:
  level:
    root: INFO
    com.mechanical.erp: DEBUG
  • level.root: 設(shè)置根日志級別。
  • level.com.mechanical.erp: 設(shè)置特定包的日志級別。

管理端點(diǎn)配置

management:
  endpoints:
    web:
      exposure:
        include: "*"
  • include: 暴露所有管理端點(diǎn)。

總結(jié)

  • application.yml (配置文件):
    • 目的: 定義 Spring Boot 應(yīng)用程序的各種配置屬性。
    • 內(nèi)容: 包含服務(wù)器配置、Spring 配置、日志配置、安全配置和其他應(yīng)用程序級別的配置。
    • 作用: 用于配置應(yīng)用程序的行為和環(huán)境,確保應(yīng)用程序能夠正確啟動和運(yùn)行。

確保這個文件中的配置正確無誤,并且符合項目的整體需求。

到此這篇關(guān)于JAVA系統(tǒng)中Spring Boot應(yīng)用程序的配置文件application.yml的文章就介紹到這了,更多相關(guān)Spring Boot配置文件application.yml內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論