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

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

  •  
  •   shanlan · 2019-03-02 01:28:52 +08:00 · 1960 次点击
    这是一个创建于 1880 天前的主题,其中的信息可能已经有所发展或是发生改变。

    初学还请包涵。

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

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

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

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

    还请不吝赐教,谢谢你。
    
    5 条回复    2019-03-02 21:23:03 +08:00
    choice4
        1
    choice4  
       2019-03-02 08:11:52 +08:00 via Android
    @PropertySources 试试呢
    shanlan
        2
    shanlan  
    OP
       2019-03-02 13:02:14 +08:00
    @choice4 试过了,亲。
    shuqin2333
        3
    shuqin2333  
       2019-03-02 15:43:27 +08:00
    看起来没有问题。用 idea 的话,如果哪个环节出了问题应该很容易看出来才对啊,如果配置正确都能直接 ctrl + 左键点过去
    shanlan
        4
    shanlan  
    OP
       2019-03-02 19:50:57 +08:00
    @shuqin2333 没搞定,暂时先放放。
    iluhcm
        5
    iluhcm  
       2019-03-02 21:23:03 +08:00
    有没有在 applicationContext 里 include applicationContext-service.xml 这个 xml ?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3320 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 13:55 · PVG 21:55 · LAX 06:55 · JFK 09:55
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.