WELD-001414 Bean name is ambiguous - Understanding @Any @Default
infinity2heaven Jan 30, 2011 5:11 PMI have a sample project extending weld-login example that comes with weld-1.1 dist.
Bean
@Model
public class Credentials {
private String username;
private String password;
}
Authenticator
@SessionScoped
@Named
public class Authenticator
implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private Credentials credentials;
private User currentUser;
@PersistenceContext
private EntityManager em;
@SuppressWarnings( "unchecked" )
public void login() {
List< User > results =
em.createQuery(
"select u from User u where u.credential.username=:username and u.credential.password=:password" ).setParameter(
"username",
credentials.getUsername() ).setParameter( "password", credentials.getPassword() ).getResultList();
if ( !results.isEmpty() ) {
currentUser = results.get( 0 );
FacesContext.getCurrentInstance().addMessage(
null,
new FacesMessage( "Welcome, " + currentUser.getName() ) );
}
}
public void logout() {
FacesContext.getCurrentInstance().addMessage(
null,
new FacesMessage( "Goodbye, " + currentUser.getName() ) );
currentUser = null;
}
public boolean isLoggedIn() {
return currentUser != null;
}
@Produces
@LoggedIn
public User getCurrentUser() {
return currentUser;
}
@SuppressWarnings( "unchecked" )
@Produces
@Named
@RequestScoped
public List< User > getUsers() {
return em.createQuery( "select u from User u" ).getResultList();
}
}
I get the following on deploying to JBoss 6.0. I'm using Sea, 3.0 beta, Seam-solder jars in my war file. And that's the only difference from the weld-login project (which I'm abel to run and deploy).
WELD-001414 Bean name is ambiguous. Name credentials resolves to beans [Managed Bean [class xxx.security.Credentials] with qualifiers [@Any @Default], Managed Bean [class org.jboss.seam.security.CredentialsImpl] with qualifiers [@Any @Default @Named]] at org.jboss.weld.bootstrap.Validator.validateBeanNames(Validator.java:472) [:6.0.0.Final]
I don't think I understand the concepts of @Any, @Default at all. What is the wrong with the above code (since it works in the example project)