Sirish V
Sirish V

Reputation: 932

Unable to deploy WAR in an EAR on WebLogic

I have a web application running on JSF 2.2 on WebLogic Application server 12.2.1.1.

I have a simple java class and trying to initialize it as an ApplicationScoped object using CDI. This gets deployed perfectly fine as a WAR.

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;

@Named
@ApplicationScoped
public class AppContext {
    public AppContext() {
    }
}

However, when I add this WAR to an EAR it fails to deploy. I am trying all possible solutions and nothing seems to work at this point. The exception log is as below:

weblogic.management.DeploymentException: CDI deployment failure:WELD-001414: Bean name is ambiguous. Name appContext resolves to beans: [Managed Bean [class beans.AppContext] with qualifiers [@Default @Any @Named], Managed Bean [class beans.AppContext] with qualifiers [@Default @Any @Named]]:org.jboss.weld.exceptions.DeploymentException:WELD-001414: Bean name is ambiguous. Name appContext resolves to beans: [Managed Bean [class beans.AppContext] with qualifiers [@Default @Any @Named], Managed Bean [class beans.AppContext] with qualifiers [@Default @Any @Named]]
    at org.jboss.weld.bootstrap.Validator.validateBeanNames(Validator.java:641)
    at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:487)
    at org.jboss.weld.bootstrap.WeldStartup.validateBeans(WeldStartup.java:446)
    at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:90)
    at com.oracle.injection.provider.weld.WeldInjectionContainer.start(WeldInjectionContainer.java:150)
    Truncated. see log file for complete stacktrace

Also WEB-INF\beans.xml is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>

Application Running On:

NetBeans IDE 8.2;
JDK 1.8 b121;
Mojarra JSF 2.2;
WebLogic 12.2.1.1;

Any hint on fixing this issue is highly appreciated.

Upvotes: 5

Views: 7748

Answers (4)

Valamburi M
Valamburi M

Reputation: 702

IMHO: This looks like an issue from the context initialization perspective, i.e., The EAR classloader loads the bean into the context and the WAR also loads the bean into the context again. Please check this blog CDI in EARs, for understanding it more clearly. Some of the J2EE servers manages this by their own. Please check the way your application is packaged and also check the way how it is deployed.

Additional information to understand about the class loading check here:

  1. Understanding WebLogic Server Application Classloading
  2. Application.xml WAR EJB.jar Module order can cause ClassLoader issues

Upvotes: 1

Mauricio Gracia Gutierrez
Mauricio Gracia Gutierrez

Reputation: 10844

Remove the WAR from EAR and deploy it separately. For some reason, packaging the WAR in the EAR and deploying fails. Not sure if this is an issue with WebLogic or EAR configuration.

Taken from identical question with accepted answer - Initializing CDI Bean Name Ambiguous

Upvotes: 1

axemoi
axemoi

Reputation: 221

The fact that it deploys as a standalone WAR but fails as an EAR is a fairly clear indicator of the problem. Either the application contains an object with the same bean name from an external library or this class itself has been copied somewhere else in the EAR. Check that you're not loading this class (or jar containing this class) into any other place in the EAR; APP-INF comes to mind. If you haven't already, the quickest way to determine if it's an external library or your own deployment path is by renaming the class to something that you can ensure is unique (MyUniqueBeanName for example). If the problem persists after a rename, it's most likely your deployment.

Upvotes: 1

Anil Agrawal
Anil Agrawal

Reputation: 3026

It seems that any bean is already registered with name "appContext" in bean server.

Either provide different bean name explicitly or change the class name.

Upvotes: 0

Related Questions