V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Guidoo
V2EX  ›  程序员

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

  •  
  •   Guidoo · 2020-05-31 16:50:03 +08:00 · 2260 次点击
    这是一个创建于 1426 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    7 条回复    2020-06-01 13:09:40 +08:00
    hantsy
        1
    hantsy  
       2020-05-31 17:07:28 +08:00
    记得可以自己实现一个 AbstractGenericContextLoader,设置定义文件后缀和相应的 BeanDefinitionReader 。
    chendy
        2
    chendy  
       2020-05-31 17:20:23 +08:00
    把 spring-boot 里读 yml 文件的部分抄进来就行了…
    shylockhg
        3
    shylockhg  
       2020-05-31 17:28:35 +08:00
    额非 java 程序员,不是读一下 yaml 就可以么
    hantsy
        4
    hantsy  
       2020-05-31 17:48:20 +08:00
    @shylockhg 没那么简单,Spring Boot Yaml 是支持 SPEL 的。
    aitaii
        5
    aitaii  
       2020-05-31 18:26:17 +08:00 via Android
    snakeyaml
    DsuineGP
        6
    DsuineGP  
       2020-06-01 09:11:57 +08:00
    ```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  
       2020-06-01 13:09:40 +08:00
    用来用去,还是 toml 舒服点,yaml 的锁紧和列表语法太头疼
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1644 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 17:15 · PVG 01:15 · LAX 10:15 · JFK 13:15
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.