V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
shanlan
V2EX  ›  Java

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

  •  
  •   shanlan · Mar 2, 2019 · 2488 views
    This topic created in 2613 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
        1
    JohnZorn  
       Mar 2, 2019 via Android
    @PropertySources 试试呢
    shanlan
        2
    shanlan  
    OP
       Mar 2, 2019
    @choice4 试过了,亲。
    shuqin2333
        3
    shuqin2333  
       Mar 2, 2019
    看起来没有问题。用 idea 的话,如果哪个环节出了问题应该很容易看出来才对啊,如果配置正确都能直接 ctrl + 左键点过去
    shanlan
        4
    shanlan  
    OP
       Mar 2, 2019
    @shuqin2333 没搞定,暂时先放放。
    iluhcm
        5
    iluhcm  
       Mar 2, 2019
    有没有在 applicationContext 里 include applicationContext-service.xml 这个 xml ?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3580 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 11:08 · PVG 19:08 · LAX 04:08 · JFK 07:08
    ♥ Do have faith in what you're doing.