简体   繁体   中英

EJB Ambiguous dependencies: How to specify which class to Inject

I am trying to inject an object in my EJB like this:

@Stateless
@Path("/auth")
public class Login {

@Inject
UsernamePasswordCredentials credentials;

The problem is the UsernamePasswordCredentials has a child class and both classes have the same qualifiers which causes an ambiguous dependencies. How do I specify that I want to inject an instance of the parent class and not the child class? Error message looks like this:

Ambiguous dependencies for type UsernamePasswordCredentials with qualifiers @Default

Managed Bean [class org.picketlink.idm.credential.UsernamePasswordCredentials] with qualifiers [@Any @Default],

Managed Bean [class org.picketlink.idm.credential.TOTPCredentials] with qualifiers [@Any @Default]

You could use the programmatic lookup mechanism to restrict the actual type of the needed bean:

@Inject
Instance<UsernamePasswordCredentials> credInst;

public UserNamePasswordCredentials getCredentials() {
  return credInst.select(UsernamePasswordCredentials.class).get();
}

Beyond that, I'm not a Picket Link expert, but I think you are doing something wrong with the framework. Picket Link CDI integration was very well crafted so I'm a bit puzzled you could encounter such an issue in a standard usage.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM