How to disable WELD on WildFly
Asked Answered
P

3

12

How to fully disable WELD on WildFly. I don't need it, because I use another DI framework.

Exception 0 : javax.enterprise.inject.UnsatisfiedResolutionException: Unable to resolve a bean for 'org.springframework.data.mongodb.core.MongoOperations' with qualifiers [@javax.enterprise.inject.Any(), @javax.enterprise.inject.Default()]. at org.springframework.data.mongodb.repository.cdi.MongoRepositoryExtension.createRepositoryBean(MongoRepositoryExtension.java:104) at org.springframework.data.mongodb.repository.cdi.MongoRepositoryExtension.afterBeanDiscovery(MongoRepositoryExtension.java:79) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstanceWithSpecialValue(MethodInjectionPoint.java:93) at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:266) at org.jboss.weld.event.ExtensionObserverMethodImpl.sendEvent(ExtensionObserverMethodImpl.java:125) at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:253) at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:232) at org.jboss.weld.event.ObserverNotifier.notifyObserver(ObserverNotifier.java:169)

I tried

<?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"
   xmlns:weld="http://jboss.org/schema/weld/beans"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee    http://java.sun.com/xml/ns/javaee/beans_1_0.xsd
                       http://jboss.org/schema/weld/beans http://jboss.org/schema/weld/beans_1_1.xsd
http://jboss.org/schema/weld/beans ">

<weld:scan>
    <weld:exclude name="com.google.**"/>
    <weld:exclude name="org.springframework.data.mongodb.**"/>
</weld:scan>

But it did not resolve my problem.

Puga answered 13/2, 2014 at 14:15 Comment(0)
C
6

Try deleting or commenting out the org.jboss.as.weld extension in the extensions list on the beginning of $JBOSS_HOME/standalone/configuration/standalone.xml. You may also want to delete <subsystem xmlns="urn:jboss:domain:weld:1.0"/> from <profile>. This should cause disabling Weld for all applications deployed on the server.

Clementeclementi answered 13/2, 2014 at 14:22 Comment(1)
You can also use the CLI command to remove the subsystem. $JBOSS_HOME/bin/jboss-cli.sh -c "/subsystem=weld:remove".Vert
V
19

There's the standard way:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
                       http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
   version="1.1" bean-discovery-mode="none">
</beans>
Volkman answered 13/2, 2014 at 14:30 Comment(4)
This is the more appropriate answer, and is not app server specific. I fear many people will face this issue in coming weeks as more app servers launch w/ EE 7 compliance.Maretz
Yes, even I agree this is a better solution:)Clementeclementi
Note that the above XML should be saved as WEB-INF/beans.xml for war files, or as META-INF/beans.xml for jar files.Cooke
This disables bean scanning, yes, but the OPs question was how to disable weld... So this does not fully answer the question I think. However, maybe the OP just asks the wrong question :)Vibrissa
C
16

Option 1: jboss-all.xml in the war

This is Weld-specific, but it disables Weld's automatic bean scanning for an entire deployment (eg a war file and all the jars inside it). This is handy when you can't easily add beans.xml to a third-party jar, such as jboss-seam-resteasy.jar.

Save as WEB-INF/jboss-all.xml for wars, META-INF/jboss-all.xml otherwise:

<jboss xmlns="urn:jboss:1.0">
    <weld xmlns="urn:jboss:weld:1.0" require-bean-descriptor="true"/>
</jboss>

See Per-deployment configuration.

Option 2: standalone.xml in WildFly

Another option, which doesn't require changing the application itself, is to configure the weld subsystem not to treat random jars as CDI libraries. Just edit the configuration for weld in WildFly's standalone.xml to look like this:

<subsystem xmlns="urn:jboss:domain:weld:2.0" require-bean-descriptor="true"/>
Cooke answered 5/6, 2014 at 23:43 Comment(2)
Option 1 is the way to go :) docs.jboss.org/author/display/WFLY8/CDI+ReferenceRenee
Just adding this detail to the previous (correct) answer: for ear packages the jboss-all.xml file must be located in the ear META-INF folder.Hemorrhoid
C
6

Try deleting or commenting out the org.jboss.as.weld extension in the extensions list on the beginning of $JBOSS_HOME/standalone/configuration/standalone.xml. You may also want to delete <subsystem xmlns="urn:jboss:domain:weld:1.0"/> from <profile>. This should cause disabling Weld for all applications deployed on the server.

Clementeclementi answered 13/2, 2014 at 14:22 Comment(1)
You can also use the CLI command to remove the subsystem. $JBOSS_HOME/bin/jboss-cli.sh -c "/subsystem=weld:remove".Vert

© 2022 - 2024 — McMap. All rights reserved.