It's exactly as Joe already explained. Whenever we use client proxies in JavaEE 
(which is for *all* NormalScoped CDI beans plus all NoInterfaceView EJBs) we 
generate a dynamic subclass on the fly ('Contextual Reference') which overloads 
all the methods and delegates through to the 'Contextual Instance'

For a native class

public class User {
  private String name;
  public String getName() { return name; }
  public void setName(String name) {this.name=name;}
}

we will create a new class on the fly (see NormalScopedProxyFactory in our 
code) which is like:

public class User$$OwbNormalScopeProxy extends User {
  private User owbContextualInstanceProvider;

  @Override

  public String getName() { return owbContextualInstanceProvider.getName();};

  @Override
  public void setName(String name) { 
owbContextualInstanceProvider.setName(name); };
}

And of course this 'Contextual Reference' can only use the default constructor 
of the proxied class.
Btw, this is one of the reasons why you should always use @PostConstruct and 
not the ct to initialize your beans.

LieGrue,
strub



On Friday, 12 September 2014, 16:52, Joseph Bergmark <[email protected]> 
wrote:
 

>
>
>It may also be worth mentioning that at injection time for normal scoped beans 
>we only inject a client proxy.  It may be the construction of the proxy class 
>that is hitting your no-args constructor.  
>
>Once you invoke a method on that proxy, I would expect the @Inject constructor 
>to be called when the proxy obtains an instance form the context.
>
>
>On Fri, Sep 12, 2014 at 10:24 AM, Romain Manni-Bucau <[email protected]> 
>wrote:
>
>Hi
>>
>>did you test against 1.7? code was totally rewritten
>>
>>
>>Romain Manni-Bucau
>>Twitter: @rmannibucau
>>Blog: http://rmannibucau.wordpress.com/
>>LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>Github: https://github.com/rmannibucau
>>
>>
>>
>>2014-09-12 15:56 GMT+02:00 Martin Strohal <[email protected]>:
>>> Hi,
>>>
>>> I have a question about ApplicationScoped CDI beans with constructor
>>> injection.
>>> My bean has two constructors: one default without parameters and one
>>> with @Inject.
>>> If I inject this bean in another one, only the default constructor is
>>> executed (I've put some logging messages in both constructors). The
>>> injection constructor is not executed, so the field is null.
>>> How can that be? What am I doing wrong?
>>>
>>> (BTW: I'm using openwebbeans 1.1.8 in TomEE 1.5.2)
>>>
>>> Thanks,
>>> Martin
>>
>
>
>

Reply via email to