Java 如何在 WildFly 上禁用 WELD

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21756707/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 10:30:38  来源:igfitidea点击:

How to disable WELD on WildFly

javajbosscdiweldwildfly

提问by Rinat Mukhamedgaliev

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

如何在 WildFly 上完全禁用 WELD。我不需要它,因为我使用了另一个 DI 框架。

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)

异常 0:javax.enterprise.inject.UnsatisfiedResolutionException:无法使用限定符 [@javax.enterprise.inject.Any(), @javax.enterprise.inject 解析 'org.springframework.data.mongodb.core.MongoOperations' 的 bean 。默认()]。在 org.springframework.data.mongodb.repository.cdi.MongoRepositoryExtension.createRepositoryBean(MongoRepositoryExtension.java:104) 在 org.springframework.data.mongodb.repository.cdi.MongoRepositoryExtension.afterBeanDiscovery(MongoRepositoryExtension.java:79) .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( .java:606) 在 org.jboss.weld。

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.

但这并没有解决我的问题。

采纳答案by Petr Mensik

Try deleting or commenting out the org.jboss.as.weldextension 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.

尝试删除或注释掉org.jboss.as.weld开头的扩展列表中的扩展$JBOSS_HOME/standalone/configuration/standalone.xml。您可能还想<subsystem xmlns="urn:jboss:domain:weld:1.0"/><profile>. 这应该会导致对部署在服务器上的所有应用程序禁用 Weld。

回答by Yuri

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>

回答by seanf

Option 1: jboss-all.xml in the war

选项 1:jboss-all.xml 中的战争

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.xmlto a third-party jar, such as jboss-seam-resteasy.jar.

这是 Weld 特定的,但它会禁用 Weld 对整个部署(例如,war 文件和其中的所有 jar)的自动 bean 扫描。当您无法轻松添加beans.xml到第三方 jar 时,这很方便,例如 jboss-seam-resteasy.jar。

Save as WEB-INF/jboss-all.xmlfor wars, META-INF/jboss-all.xmlotherwise:

除了WEB-INF/jboss-all.xml战争,META-INF/jboss-all.xml否则:

<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

选项 2:WildFly 中的 standalone.xml

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.xmlto look like this:

另一个不需要更改应用程序本身的选项是配置焊接子系统,不要将随机 jar 视为 CDI 库。只需编辑 WildFly 中的焊接配置,standalone.xml如下所示:

<subsystem xmlns="urn:jboss:domain:weld:2.0" require-bean-descriptor="true"/>