• 请不要在回答技术问题时复制粘贴 AI 生成的内容
Guidoo
V2EX  ›  程序员

普通的 spring 项目可以用.yml 当配置文件吗?具体怎么实现?

  •  
  •   Guidoo · May 31, 2020 · 3114 views
    This topic created in 2361 days ago, the information mentioned may be changed or developed.

    不是 springboot 项目哈。 有个老项目,ssm 框架,想用 yml

    7 replies  •  2020-06-01 13:09:40 +08:00
    hantsy
    hantsy
    May 31, 2020
    1
    记得可以自己实现一个 AbstractGenericContextLoader,设置定义文件后缀和相应的 BeanDefinitionReader 。
    chendy
    chendy
    May 31, 2020
    2
    把 spring-boot 里读 yml 文件的部分抄进来就行了…
    shylockhg
    shylockhg
    May 31, 2020
    3
    额非 java 程序员,不是读一下 yaml 就可以么
    hantsy
    hantsy
    May 31, 2020
    4
    @shylockhg 没那么简单,Spring Boot Yaml 是支持 SPEL 的。
    aitaii
    aitaii
    May 31, 2020 via Android
    5
    snakeyaml
    DsuineGP
    DsuineGP
    Jun 1, 2020
    6
    ```xml
    <context:annotation-config/>

    <bean id="yamlProperties" class="org.springframework.beans.factory.config.YamlPropertiesFactoryBean">
    <property name="resources" value="classpath:test.yml"/>
    </bean>

    <context:property-placeholder properties-ref="yamlProperties"/>

    ```
    qW7bo2FbzbC0
    qW7bo2FbzbC0
    Jun 1, 2020
    7
    用来用去,还是 toml 舒服点,yaml 的锁紧和列表语法太头疼
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2383 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 12:48 · PVG 20:48 · LAX 04:48 · JFK 07:48
    ♥ Do have faith in what you're doing.