java - spring 模板方法模式 注入属性的问题
ringa_lee
ringa_lee 2017-04-18 10:11:52
0
2
325
asbtract class A {
    private String attr = "";
}
class B extends A {
    @Value("${xxx}")
    private String attr;
}

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

ringa_lee
ringa_lee

ringa_lee

reply all(2)
Ty80

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

PHPzhong

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!