JinTianYi456
V2EX  ›  Java

spring-boot+spring-cloud, 基础的加载配置代码如何脱离容器来运行?

  •  
  •   JinTianYi456 · Aug 15, 2022 · 2465 views
    This topic created in 1547 days ago, the information mentioned may be changed or developed.
    StandardEnvironment environment = new StandardEnvironment();
    
    // begin: application.* files
    // 最好用 version 2.3 来, 2.4 被标记 Deprecated
    new ConfigFileApplicationListener().postProcessEnvironment(environment, application);
    // end: application.* files
    
    // begin: bootstrap.* files
    // TODO 感觉和 org.springframework.cloud.bootstrap.BootstrapApplicationListener 有关,但我不会了
    // end: bootstrap.* files
    
    // 然后就能读取配置了
    // environment.getProperty(
    
    5 replies  •  2022-08-16 13:07:59 +08:00
    siweipancc
    siweipancc
    Aug 16, 2022 via iPhone
    1
    这啥,学习日记?
    JinTianYi456
    JinTianYi456
    OP
    Aug 16, 2022
    2
    @siweipancc #1 问-问题。
    DreamSpace
    DreamSpace
    Aug 16, 2022
    3
    没看懂,到底想问啥啊?是想脱离 Spring 容器来访问 spring 配置吗?
    frank1256
    frank1256
    Aug 16, 2022
    4
    ?没明白你表达的意思,你的意思是,自定义配置加载类吗?那就自定义 starter 就行了,exclude 默认的 starter 。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   948 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 20:03 · PVG 04:03 · LAX 12:03 · JFK 15:03
    ♥ Do have faith in what you're doing.