java

关注公众号 jb51net

关闭
首页 > 软件编程 > java > Spring Boot配置文件application.yml

JAVA系统中Spring Boot应用程序的配置文件application.yml使用详解

作者:天之涯上上

这篇文章主要介绍了JAVA系统中Spring Boot应用程序的配置文件application.yml的相关资料,application.yml是Spring Boot应用程序的配置文件,定义了服务器、Spring、日志、安全及其他配置属性,确保应用程序正确启动和运行,需要的朋友可以参考下

backend\src\main\resources\application.yml 是一个配置文件,用于定义 Spring Boot 应用程序的各种配置属性。这个文件通常包含数据库连接、服务器设置、日志配置、安全设置以及其他应用程序级别的配置。

文件路径

backend\src\main\resources\application.yml

文件内容

以下是一个典型的 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

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

3. Logging 配置

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

4. Management 配置

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

5. Security 配置

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

6. 自定义配置

custom:
  app:
    feature-flag:
      new-ui: true
    timeout:
      default: 30s

使用示例

以下是一些常见的配置项及其用途:

数据库连接配置

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

JPA 配置

spring:
  jpa:
    hibernate:
      ddl-auto: update
    show-sql: true
    properties:
      hibernate:
        dialect: org.hibernate.dialect.MySQL5InnoDBDialect
        format_sql: true

日志配置

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

管理端点配置

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

总结

确保这个文件中的配置正确无误,并且符合项目的整体需求。

到此这篇关于JAVA系统中Spring Boot应用程序的配置文件application.yml的文章就介绍到这了,更多相关Spring Boot配置文件application.yml内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:
阅读全文