When trying to inject arguments into the constructor of a CDI bean (ApplicationScoped), I\'m encountering the following issue:
Caused by: org.jboss.weld.exceptio
I think Vladimir is pointing you to the right direction.
I'm just learning CDI (and Weld) therefore my answer might not be 100% accurate in all aspects, but it seems like you need to pick a type at injection point that has a no arg constructor.
I hit the same error today with the next type hierarchy:
IServerInterceptor
interface,AuthenticationInterceptor
that has one constructor that takes dependencies (fun fact: this knows nothing about (C)DI),InjectableAuthenticationInterceptor
which has only one injected constructor.I have another bean where I would like to inject an instance of AuthenticationInterceptor
. It works, when I define the field as type IServerInterceptor
(as it is an interface and weld can create a proxy for it(?)), but it stops working when I define the field as AuthenticationInterceptor
.
With some code:
// IServerInterceptor.java
public interface IServerInterceptor {
}
// AuthenticationInterceptor.java
public class AuthenticationInterceptor extends InterceptorAdapter {
private final Predicate validAccessTokenString;
private final Function toAccessTokenModel;
private final LoginManager loginManager;
public AuthenticationInterceptor(Predicate validAccessTokenString, Function toAccessTokenModel, LoginManager loginManager) {
this.validAccessTokenString = validAccessTokenString;
this.toAccessTokenModel = toAccessTokenModel;
this.loginManager = loginManager;
}
// ...
}
// InjectableAuthenticationInterceptor.java
@ApplicationScoped
public class InjectableAuthenticationInterceptor extends AuthenticationInterceptor {
@Inject
public InjectableAuthenticationInterceptor(LoginManager loginManager) {
super(isWelformedAccessToken(), toAccessToken(), loginManager);
}
}
Now,
@Inject private IServerInterceptor authenticationInterceptor;
works great, but
@Inject private AuthenticationInterceptor authenticationInterceptor;
does not.