bike part reward : setting bean ID property automatically
Brent Putman
putmanb at georgetown.edu
Thu Feb 6 22:41:54 EST 2014
On 2/6/14 8:51 PM, Brent Putman wrote:
>
> On 2/6/14 8:41 PM, Brent Putman wrote:
>>
>> I think that's done pretty easily automagically with a
>> BeanPostProcessor that does something like:
>>
>> Object postProcessBeforeInitialization(Object bean, String beanName)
>> throws BeansException {
>> if (bean instanceof IdentifiableComponent) {
>> ((IdentifiableComponent)bean).setID(beanName);
>> }
>> }
>>
>
> Actually, looks like that interface doesn' define a setID method, and
> even the abstract impls I see in java-support currently expose it as a
> protected method, not public. I can't look at any of our concrete
> impls until I get back to a working Eclipse workspace, so I don't know
> if any of them actually expose this in a useful way (probably not).
Yeah, not seeing any candiates for this as far as public methods. I'd
say that if this is important enough, you'd either have to put a public
setId(..) on the IdentifiableComponent interface (which may not really
in general be a good idea), or else rely on the fact that the private
variable is usually/always named 'id' and set it via reflection or
something.
Which reminds me: The latter (reflection) sounds somewhat horrible and
it is. However, on a related note, because Spring sets properties via
reflection, it actually does this routinely. Recently in another
project I discovered I was mistakenly creating an XML wired bean via
invokation of a protected (or private?) constructor on something. And
you probably know that with their annotation support you can @Autowired
a private variable which doesn't even have a getter/setter. So maybe it
isn't that crazy.... as long as we standardize on 'id' as the class
variable name.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://shibboleth.net/pipermail/dev/attachments/20140206/bd449e5c/attachment.html
More information about the dev
mailing list