CDI installs proxies for beans of all scopes except for the @Dependent
pseudo scope. A @Produces
annotated method (short producer) is called by CDI whenever it needs to get a (new) instance of a bean. This instance is then put into some pool for the corresponding scope.
The proxy will always return the bean-instance from the pool. Try adding some debug message to the producer method to see how often it will be called. A producer for an @ApplicationScoped
bean should be called only once, and a @RequestScoped
producer should be called once per request.
In the examples above no scope is given to the producer method (the scope of the factory class is not used for the producer method), so the default scope (@Dependent) will be used. And this means (as no proxy is used for this scope), a new instance will be injected every time @Inject A
is found by CDI. See also this Question and Answer and the referenced documentation for more details.
So to your concrete questions:
- The observed behavior is expected
- Proxies will only be used if scope is not
@Dependet
which is the default.