JAVA系統(tǒng)中Spring?Boot應(yīng)用程序的配置文件application.yml使用詳解
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ù)庫模式(例如
update
,create
,create-drop
)。 - show-sql: 是否在控制臺顯示 SQL 語句。
- properties.hibernate.dialect: 指定使用的 Hibernate 方言。
- properties.hibernate.format_sql: 是否格式化 SQL 語句。
- hibernate.ddl-auto: 指定 Hibernate 如何自動處理數(shù)據(jù)庫模式(例如
- 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)文章
ByteArrayInputStream簡介和使用_動力節(jié)點(diǎn)Java學(xué)院整理
ByteArrayInputStream 是字節(jié)數(shù)組輸入流。它繼承于InputStream。這篇文章主要介紹了ByteArrayInputStream簡介和使用_動力節(jié)點(diǎn)Java學(xué)院整理,需要的朋友可以參考下2017-05-05Java中通過jsch來連接遠(yuǎn)程服務(wù)器執(zhí)行l(wèi)inux命令
這篇文章主要介紹了Java中通過jsch來連接遠(yuǎn)程服務(wù)器執(zhí)行l(wèi)inux命令的相關(guān)資料,需要的朋友可以參考下2016-03-03SpringMvc3+extjs4實(shí)現(xiàn)上傳與下載功能
這篇文章主要為大家詳細(xì)介紹了SpringMvc3+extjs4實(shí)現(xiàn)上傳與下載功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-06-06Spring?cloud網(wǎng)關(guān)gateway進(jìn)行websocket路由轉(zhuǎn)發(fā)規(guī)則配置過程
這篇文章主要介紹了Spring?cloud網(wǎng)關(guān)gateway進(jìn)行websocket路由轉(zhuǎn)發(fā)規(guī)則配置過程,文中還通過實(shí)例代碼介紹了Spring?Cloud?Gateway--配置路由的方法,需要的朋友可以參考下2023-04-04Java給實(shí)體每一個字段賦默認(rèn)值詳細(xì)代碼示例
這篇文章主要給大家介紹了關(guān)于Java給實(shí)體每一個字段賦默認(rèn)值的相關(guān)資料,在編程過程中有時會出現(xiàn)這樣一種情況,在查詢無結(jié)果時我們需要給實(shí)體賦默認(rèn)值,需要的朋友可以參考下2023-09-09RxJava2 Scheduler使用實(shí)例深入解析
這篇文章主要為大家介紹了RxJava2 Scheduler使用實(shí)例深入解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10IDEA下創(chuàng)建SpringBoot+MyBatis+MySql項目實(shí)現(xiàn)動態(tài)登錄與注冊功能
這篇文章主要介紹了IDEA下創(chuàng)建SpringBoot+MyBatis+MySql項目實(shí)現(xiàn)動態(tài)登錄與注冊功能,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-02-02