org.jboss.classfilewriter.DuplicateMemberException
Posted
技术标签:
【中文标题】org.jboss.classfilewriter.DuplicateMemberException【英文标题】: 【发布时间】:2018-11-26 02:44:11 【问题描述】:在 Wildfly 上部署我的应用程序时,我收到以下错误:
17:28:25,571 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-3) MSC000001: Failed to start service jboss.deployment.unit."Restaurant-1.1-SNAPSHOT.war".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."Restaurant-1.1-SNAPSHOT.war".WeldStartService: Failed to start service
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1904)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.jboss.weld.exceptions.WeldException: WELD-001524: Unable to load proxy class for bean Managed Bean [class com.naigoapps.restaurant.model.dao.RestaurantTableDao] with qualifiers [@Any @Default] with class class com.naigoapps.restaurant.model.dao.RestaurantTableDao using classloader ModuleClassLoader for Module "deployment.Restaurant-1.1-SNAPSHOT.war:main" from Service Module Loader
at org.jboss.weld.bean.proxy.ProxyFactory.getProxyClass(ProxyFactory.java:371)
at org.jboss.weld.injection.producer.SubclassedComponentInstantiator.createEnhancedSubclass(SubclassedComponentInstantiator.java:114)
at org.jboss.weld.injection.producer.SubclassedComponentInstantiator.initEnhancedSubclass(SubclassedComponentInstantiator.java:86)
at org.jboss.weld.injection.producer.SubclassedComponentInstantiator.<init>(SubclassedComponentInstantiator.java:79)
at org.jboss.weld.injection.producer.SubclassedComponentInstantiator.forInterceptedDecoratedBean(SubclassedComponentInstantiator.java:63)
at org.jboss.weld.injection.producer.BeanInjectionTarget.initializeAfterBeanDiscovery(BeanInjectionTarget.java:121)
at org.jboss.weld.injection.producer.InjectionTargetInitializationContext.initialize(InjectionTargetInitializationContext.java:42)
at org.jboss.weld.injection.producer.InjectionTargetService.initialize(InjectionTargetService.java:63)
at org.jboss.weld.bootstrap.WeldStartup.deployBeans(WeldStartup.java:433)
at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:83)
at org.jboss.as.weld.WeldStartService.start(WeldStartService.java:95)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
... 3 more
Caused by: org.jboss.weld.exceptions.WeldException: Method already exists. Method: getTargetClass Parameters:[] Return Type: Ljava/lang/Class;
at org.jboss.weld.bean.proxy.InterceptedSubclassFactory.addSpecialMethods(InterceptedSubclassFactory.java:386)
at org.jboss.weld.bean.proxy.InterceptedSubclassFactory.addMethods(InterceptedSubclassFactory.java:116)
at org.jboss.weld.bean.proxy.ProxyFactory.createProxyClass(ProxyFactory.java:469)
at org.jboss.weld.bean.proxy.ProxyFactory.getProxyClass(ProxyFactory.java:364)
... 15 more
Caused by: : Method already exists. Method: getTargetClass Parameters:[] Return Type: Ljava/lang/Class;
at org.jboss.classfilewriter.ClassFile.addMethod(ClassFile.java:133)
at org.jboss.classfilewriter.ClassFile.addMethod(ClassFile.java:148)
at org.jboss.weld.bean.proxy.InterceptedSubclassFactory.addSpecialMethods(InterceptedSubclassFactory.java:378)
... 18 more
这些是我的源文件:
public interface Dao<E extends BaseEntity>
public Class<E> getTargetClass();
public String getOrderByClause();
public abstract class AbstractDao<E extends BaseEntity> implements Dao<E>
[...]
@Override
public String getOrderByClause()
return null;
public class RestaurantTableDao extends AbstractDao<RestaurantTable>
@Override
public String getOrderByClause()
return "name";
@Override
public Class<RestaurantTable> getTargetClass()
return RestaurantTable.class;
似乎抽象类和接口中定义的方法有些问题。 在添加 2 个方法 getOrderByClause 和 getTargetClass 之前没有出现问题
【问题讨论】:
【参考方案1】:这是一个巧合(或命运?),Weld 的 proxy classes 定义 getTargetClass()
方法以及具有相同的签名,考虑到帐户类型擦除。
因此,正如例外所说:
org.jboss.weld.exceptions.WeldException:
Method already exists.
Method: getTargetClass Parameters:[] Return Type: Ljava/lang/Class;
...因为这就是 Weld 的工作方式,所以最安全、最简单、最快捷的方法就是重命名您的方法。
奖励: 如果您想知道到底是什么代理,这里有一个来自 Stuart Douglas 的关于 Weld 的简短 article,它已经很老了,但仍然是重点。
【讨论】:
我认为问题与继承或类似的东西有关...我只是选择了错误的方法名称,多么巧合!以上是关于org.jboss.classfilewriter.DuplicateMemberException的主要内容,如果未能解决你的问题,请参考以下文章