Hi guys,

This question is more generic than TomEE related however I decided to ask
here because you TomEE devs might have a better internal look on this.

What I'm trying to do is to inject a primitive value into a bean field from
some configuration file but leaving it's default value if config is not
found.

/@Inject @Config("someValue")
private Integer someValue = 4;/

I have a producer looking like this
/public @Produces @Config Integer getIntProperty(InjectionPoint p) {
  ...
  if (p.getMember() instanceof Field) {
    Field injectionField = (Field) p.getMember();
    injectionField.setAccessible(true);
                
    CreationalContext<?> cc =
beanManager.createCreationalContext(p.getBean());
    Object target = beanManager.getReference(p.getBean(),
p.getBean().getBeanClass(), cc);
                        
    try {
      // I want first fetch a default value and then return either a config
value if it's not null or default value
      Object defaultValue = injectionField.get(target);
    } catch (Exception e) {}
}/

The issue here is that the field value on the bean is always null. I suspect
this is because a bean is a proxy and there is a delegate instance
somewhere.
So my question what is the proper way of accessing the bean private fields?
I've been looking at portable extenstions and eventually found some example
that might help but it seems a bit overhead to me. Is there an easy way of
doing this?



--
View this message in context: 
http://openejb.979440.n4.nabble.com/How-to-access-a-bean-private-field-during-injection-tp4658743.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Reply via email to