Home  >  Q&A  >  body text

java - spring 模板方法模式 注入属性的问题

asbtract class A {
    private String attr = "";
}
class B extends A {
    @Value("${xxx}")
    private String attr;
}

假如properties里面的xxx的值为“123”,配置了一个bean名叫a, a.attr的值是多少?“” 还是 “123”?

ringa_leeringa_lee2766 days ago334

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-04-18 10:13:52

    My new is of course ""
    The one managed by spring is "123"

    reply
    0
  • PHPz

    PHPz2017-04-18 10:13:52

    I think it should be "", because member variables are statically bound, which means they are determined at compile time. The type of a at compile time is class A.

    reply
    0
  • Cancelreply