How to Solve Wildfly Error Message WELD-001414: Bean name is ambiguous. Name basicInputTextDBView resolves to beans: [Managed Bean [class com.mycompany.web.view.BasicInputTextDBView] when deploying Java Web Application to Wildfly

Posted on

Introduction

Another article in this context is discussing about how to solve an error message appear upon deploying a Java web application running using Primefaces framework. In this context, the condition for the error to appear is not the matter of the framework utility. It is in the availability of the Java Bean which is using an annotation. Before going further, the following is the error message appear in the Output tab of the NetBeans IDE :

Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001414: Bean name is ambiguous. Name basicInputTextDBView resolves to beans: [Managed Bean [class com.mycompany.web.view.BasicInputTextDBView] with qualifiers [@Default @Named @Any], Managed Bean [class com.mycompany.web.view.DBConnectionTestView] with qualifiers [@Default @Named @Any]]

    at org.jboss.weld.core@3.1.8.Final//org.jboss.weld.bootstrap.Validator.validateBeanName(Validator.java:653)
    at org.jboss.weld.core@3.1.8.Final//org.jboss.weld.bootstrap.ConcurrentValidator$5.doWork(ConcurrentValidator.java:121)
    at org.jboss.weld.core@3.1.8.Final//org.jboss.weld.bootstrap.ConcurrentValidator$5.doWork(ConcurrentValidator.java:119)
    at org.jboss.weld.core@3.1.8.Final//org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:62)
    at org.jboss.weld.core@3.1.8.Final//org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:55)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:833)
    at org.jboss.threads@2.4.0.Final//org.jboss.threads.JBossThread.run(JBossThread.java:513)

12:59:32,598 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 2) WFLYCTL0013: Operation ("full-replace-deployment") failed - address: ([]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"app-1.0-SNAPSHOT.war\".WeldStartService" => "Failed to start service
    Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001414: Bean name is ambiguous. Name basicInputTextDBView resolves to beans: [Managed Bean [class com.mycompany.web.view.BasicInputTextDBView] with qualifiers [@Default @Named @Any], Managed Bean [class com.mycompany.web.view.DBConnectionTestView] with qualifiers [@Default @Named @Any]]"}}
12:59:32,612 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) WFLYSRV0016: Replaced deployment "app-1.0-SNAPSHOT.war" with deployment "app-1.0-SNAPSHOT.war"
12:59:32,612 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 2) WFLYCTL0183: Service status report
WFLYCTL0186:   Services which failed to start:      service jboss.deployment.unit."app-1.0-SNAPSHOT.war".WeldStartService: Failed to start service
WFLYCTL0448: 43 additional services are down due to their dependencies being missing or failed

How to Solve Error Message Bean name is ambiguous

So, there is a solution for solving the error message. Just after looking at the above error message description. Because there is a hint or an information which is giving the clue about what is the cause of the error message as follow :

Bean name is ambiguous. Name basicInputTextDBView resolves to beans: [Managed Bean [class com.mycompany.web.view.BasicInputTextDBView] with qualifiers [@Default @Named @Any], Managed Bean [class com.mycompany.web.view.DBConnectionTestView] with qualifiers [@Default @Named @Any]]"}}

There is a bean name which is ambiguous. That bean name is ‘basicInputTextDBView’. Furthermore, that bean name in the Java web application project acts as a name which is resolving or identifying the Java Managed Bean class of ‘com.mycompany.web.view.BasicInputTextDBView’ and also ‘DBConnectionTestView’. In other words, there are two Java Bean with the same bean name. The solution is to check both of the Java Bean file. After checking both of file, as the information or hint describing the cause, both of the file have the same bean name as follow.

The first one is the first Java bean file with the name of ‘BasicInputTextDBView’. It already has the bean name of ‘basicInputTextDBView’ in the first place :

/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Clasfs.java to edit this template
 */
package com.mycompany.web.view;

import com.mycompany.web.db.DBConnection;
import java.io.Serializable;
import java.sql.Connection;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
/**
 *
 * @author Mark Spectre
 */
@Named(value = "basicInputTextDBView")
@ViewScoped
public class BasicInputTextDBView implements Serializable {

}

The second one which is also a Java bean file with the name of ‘DBConnectionTestView.java’. It also has the bean name of ‘basicInputTextDBView’.

/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.mycompany.web.view;

import com.mycompany.web.db.DBConnection;
import java.io.Serializable;
import java.sql.Connection;
import javax.faces.view.ViewScoped;
import javax.inject.Named;

/**
 *
 * @author Mark Spectre
 */
@Named(value = "basicInputTextDBView")
@ViewScoped
public class DBConnectionTestView implements Serializable {

}

In that case, in order to solve the problem by avoiding conflict between different Java bean file, just change the bean name of one of the Java bean file. Since there is a pattern where there is a consideration to use the same name bean value with the Java bean file but with the starting letter as a non-capital letter, the following is the change as the revision :

@Named(value = "dbConnectionTestView")
@ViewScoped
public class DBConnectionTestView implements Serializable {

}

Leave a Reply