V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
Guidoo
V2EX  ›  程序员

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

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

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

    7 replies    2020-06-01 13:09:40 +08:00
    hantsy
        1
    hantsy  
       May 31, 2020
    记得可以自己实现一个 AbstractGenericContextLoader,设置定义文件后缀和相应的 BeanDefinitionReader 。
    chendy
        2
    chendy  
       May 31, 2020
    把 spring-boot 里读 yml 文件的部分抄进来就行了…
    shylockhg
        3
    shylockhg  
       May 31, 2020
    额非 java 程序员,不是读一下 yaml 就可以么
    hantsy
        4
    hantsy  
       May 31, 2020
    @shylockhg 没那么简单,Spring Boot Yaml 是支持 SPEL 的。
    aitaii
        5
    aitaii  
       May 31, 2020 via Android
    snakeyaml
    DsuineGP
        6
    DsuineGP  
       Jun 1, 2020
    ```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
        7
    qW7bo2FbzbC0  
       Jun 1, 2020
    用来用去,还是 toml 舒服点,yaml 的锁紧和列表语法太头疼
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5120 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 207ms · UTC 05:59 · PVG 13:59 · LAX 22:59 · JFK 01:59
    ♥ Do have faith in what you're doing.