亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

 更新時(shí)間: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)用程序正確啟動(dòng)和運(yùn)行,需要的朋友可以參考下

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

文件路徑

backend\src\main\resources\application.yml

文件內(nèi)容

以下是一個(gè)典型的 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)聽(tīng)的端口號(hào)。
  • 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)用程序的名稱(chēng)。
  • datasource: 數(shù)據(jù)庫(kù)連接配置,包括 URL、用戶(hù)名、密碼和驅(qū)動(dòng)類(lèi)名。
  • jpa:
    • hibernate.ddl-auto: 指定 Hibernate 如何自動(dòng)處理數(shù)據(jù)庫(kù)模式(例如 updatecreatecreate-drop)。
    • show-sql: 是否在控制臺(tái)顯示 SQL 語(yǔ)句。
    • properties.hibernate.dialect: 指定使用的 Hibernate 方言。
    • properties.hibernate.format_sql: 是否格式化 SQL 語(yǔ)句。
  • security.user: 默認(rèn)用戶(hù)的安全配置,包括用戶(hù)名和密碼。

3. Logging 配置

logging:
  level:
    root: INFO
    com.mechanical.erp: DEBUG
  • root: 設(shè)置根日志級(jí)別為 INFO。
  • com.mechanical.erp: 設(shè)置特定包的日志級(jí)別為 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í)時(shí)間。

使用示例

以下是一些常見(jiàn)的配置項(xiàng)及其用途:

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

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ù)庫(kù)連接 URL。
  • username: 數(shù)據(jù)庫(kù)用戶(hù)名。
  • password: 數(shù)據(jù)庫(kù)密碼。
  • driver-class-name: JDBC 驅(qū)動(dòng)類(lèi)名。

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ù)庫(kù)模式。
  • show-sql: 是否在控制臺(tái)顯示 SQL 語(yǔ)句。
  • dialect: 指定使用的 Hibernate 方言。
  • format_sql: 是否格式化 SQL 語(yǔ)句。

日志配置

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

管理端點(diǎn)配置

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

總結(jié)

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

確保這個(gè)文件中的配置正確無(wú)誤,并且符合項(xiàng)目的整體需求。

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

相關(guān)文章

最新評(píng)論