自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

SpringCloud項(xiàng)目開發(fā)中實(shí)用技巧總結(jié)

開發(fā) 前端
如果使用 Spring Boot 配置日志設(shè)置,則應(yīng)將此配置放在 bootstrap.[yml | properties] 中,以便將其應(yīng)用于所有事件。

環(huán)境:SpringBoot2.7.12 + SpringCloud2021.0.7

1. 日志配置

如果使用 Spring Boot 配置日志設(shè)置,則應(yīng)將此配置放在 bootstrap.[yml | properties] 中,以便將其應(yīng)用于所有事件。注意:為了讓 Spring Cloud 正確初始化日志配置,不能使用自定義前綴。例如,在初始化日志系統(tǒng)時(shí),Spring Cloud 無法識(shí)別使用 custom.loggin.logpath 的情況。

2. 配置發(fā)生變化

應(yīng)用程序會(huì)偵聽EnvironmentChangeEvent事件,并以幾種標(biāo)準(zhǔn)方式對變化做出反應(yīng)。當(dāng)EnvironmentChangeEvent事件被監(jiān)聽到時(shí),它將收到發(fā)生變化的keys,應(yīng)用程序?qū)?huì)做如下處理:

  • 重新綁定@ConfigurationProperties的Bean對象
    監(jiān)聽器:ConfigurationPropertiesRebinder
  • 為 logging.level.* 中的任何屬性設(shè)置日志記錄器級(jí)別。
    監(jiān)聽器:LoggingRebinder

你也可以自定義監(jiān)聽EnvironmentChangeEvent事件

@Component
public class PackApplicationEventListener implements ApplicationListener<EnvironmentChangeEvent> {


  @Override
  public void onApplicationEvent(EnvironmentChangeEvent event) {
    System.out.println(event.getKeys()) ;
  }
}

3. @RefreshScope不是什么都能刷新

那些只能初始化一次的 Bean 上使用 @RefreshScope 注解。如果某個(gè) Bean 是 "不可變"的,則必須使用 @RefreshScope 注解或通過如下配置指明完整的類名:

spring:
  cloud: 
    refresh: 
      extra-refreshable: com.pack.PackUser

注意:

如果你使用的數(shù)據(jù)源 Bean 是 HikariDataSource,則無法刷新。這是 spring.cloud.refresh.never-refreshable 的默認(rèn)值。如果需要刷新,請選擇不同的數(shù)據(jù)源實(shí)現(xiàn)。

4. 加密與解密

Spring Cloud 有一個(gè)環(huán)境預(yù)處理器,用于在本地解密屬性值??梢允褂?{cipher}* 形式的加密值,只要存在有效的密鑰,它們就會(huì)在主應(yīng)用程序上下文獲得環(huán)境設(shè)置之前被解密。要在應(yīng)用程序中使用加密功能,需要在類路徑中包含 Spring Security RSA(Maven 坐標(biāo):org.springframework.security:spring-security-rsa)。

#加密配置
encrypt:
  key: aaaabbbbccccdddd
  salt: dead
#---
#加密關(guān)鍵信息
db:
  password: '{cipher}6c05a3e62aa1f71b814fd283fc15197ec18a83b67d9da27dcb63c1b3925d68c1'

這里默認(rèn)使用的AES算法,所以通過如下方式生成密文即可

TextEncryptor textEncryptor = new EncryptorFactory("xxx").create("xxxx") ;
textEncryptor.encrypt(...)

5. Acturator接口

對于 Spring Boot Actuator 應(yīng)用程序,還提供了一些額外的管理端點(diǎn):

  • POST 到 /actuator/env,以更新環(huán)境并重新綁定 @ConfigurationProperties 和日志級(jí)別。要啟用此端點(diǎn),必須設(shè)置 management.endpoint.env.post.enabled=true。
  • /actuator/refresh 重新加載引導(dǎo)帶上下文并刷新 @RefreshScope Bean。
  • /actuator/restart 關(guān)閉 ApplicationContext 并重新啟動(dòng)(默認(rèn)禁用)。
  • /actuator/pause 和 /actuator/resume,用于調(diào)用生命周期方法(ApplicationContext 上的 stop() 和 start())。

6. 自定義屬性源

通過 spring.factories添加 PropertySourceLocator 類型的 Bean 來添加其他屬性源。如下示例:

public class CustomPropertySourceLocator implements PropertySourceLocator {


  @Override
  public PropertySource<?> locate(Environment environment) {
    Map<String, Object> values = new HashMap<>() ;
    values.put("config.mq.queue", "pack.test.queue") ;
    MapPropertySource source = new MapPropertySource("PACK", values) ;
    return source ;
  }


}

在spring.factories中添加如下配置

org.springframework.cloud.bootstrap.BootstrapConfiguration=\
com.pack.CustomPropertySourceLocator

以上是本篇文章的全部內(nèi)容,希望對你有幫助。

責(zé)任編輯:武曉燕 來源: Spring全家桶實(shí)戰(zhàn)案例源碼
相關(guān)推薦

2022-10-11 08:00:47

多線程開發(fā)技巧

2020-03-09 10:31:58

vue前端開發(fā)

2009-12-21 15:50:39

2009-09-04 10:27:28

Linux實(shí)用技巧linux操作系統(tǒng)linux

2022-03-23 09:18:10

Git技巧Linux

2011-08-11 22:35:58

投影機(jī)常見問題

2009-01-03 09:34:30

ASP.NET.NET性能優(yōu)化

2011-04-08 15:40:01

Oracle認(rèn)證

2022-11-03 10:28:59

PandasSAC機(jī)制

2024-05-17 08:52:43

SQL實(shí)用技巧行列轉(zhuǎn)換

2009-07-24 11:25:15

asp.net編程

2025-03-03 00:15:00

JavaScript開發(fā)效率

2009-12-23 17:32:35

Linux構(gòu)建軟路由

2019-10-10 16:31:51

PyCharmPythonWindows

2010-09-14 10:41:24

DIV+CSS排版

2009-12-09 11:21:30

Linux實(shí)用技巧

2019-11-25 10:12:59

Python技巧工具

2010-10-08 15:44:17

vim

2019-12-22 23:10:19

LinuxSSH加密

2024-04-16 08:24:58

Python_str__()方法字符串
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)