shanlan
V2EX  ›  Java

SSM 在 Service 层使用 Value 注解注入 properties 文件报错 404

  •  
  •   shanlan · Mar 2, 2019 · 2893 views
    This topic created in 2804 days ago, the information mentioned may be changed or developed.

    初学还请包涵。

    为了解决硬编码问题,所以想在在 Service 层里,使用 Value 注解,来个变量初始化。

    properties 文件我配置在 applicationContext-service.xml 、springmvc.xml 里,程序均报错无法解析。

    注解是这样写的: @Value("${customerDaoVoSize}") private String size;

    properties 是这样配置的: <context:property-placeholder location="classpath:service.properties" />

    还请不吝赐教,谢谢你。
    
    5 replies  •  2019-03-02 21:23:03 +08:00
    JohnZorn
    JohnZorn
    Mar 2, 2019 via Android
    1
    @PropertySources 试试呢
    shanlan
    shanlan
    OP
    Mar 2, 2019
    2
    @choice4 试过了,亲。
    shuqin2333
    shuqin2333
    Mar 2, 2019
    3
    看起来没有问题。用 idea 的话,如果哪个环节出了问题应该很容易看出来才对啊,如果配置正确都能直接 ctrl + 左键点过去
    shanlan
    shanlan
    OP
    Mar 2, 2019
    4
    @shuqin2333 没搞定,暂时先放放。
    iluhcm
    iluhcm
    Mar 2, 2019
    5
    有没有在 applicationContext 里 include applicationContext-service.xml 这个 xml ?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2976 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 11:18 · PVG 19:18 · LAX 03:18 · JFK 06:18
    ♥ Do have faith in what you're doing.