gpt4 book ai didi

JAVA - WELD 装饰器错误

转载 作者:行者123 更新时间:2023-11-30 03:15:47 25 4
gpt4 key购买 nike

我尝试在 Weld 中制作装饰器,但 Weld 返回错误。我不明白我的错误是什么。我使用了相同的 Weld 示例“weld-se-numberguess”,并创建了一个装饰器扩展游戏。

 Set 18, 2015 3:41:02 PM org.jboss.weld.bootstrap.WeldStartup <clinit>
INFO: WELD-000900: 2.2.16 (Final)
Set 18, 2015 3:41:03 PM org.jboss.weld.bootstrap.WeldStartup startContainer
INFO: WELD-000101: Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
Exception in thread "main" org.jboss.weld.exceptions.DefinitionException: WELD-001455: Decorator [class org.jboss.weld.environment.se.example.numberguess.GameDecorator] decorates [] with delegate type [Game] and delegate qualifiers [@Default] does not declare any decorated types.
at org.jboss.weld.bootstrap.Validator.validateDecorator(Validator.java:570)
at org.jboss.weld.bootstrap.ConcurrentValidator$3.doWork(ConcurrentValidator.java:96)
at org.jboss.weld.bootstrap.ConcurrentValidator$3.doWork(ConcurrentValidator.java:94)
at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:60)
at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:53)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

pom.xml

<dependencies>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se</artifactId>
</dependency>

<dependency>
<groupId>javax.ejb</groupId>
<artifactId>javax.ejb-api</artifactId>
<version>3.2</version>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.2</version>
</dependency>
</dependencies>

GameDecorator.java

@Decorator
public abstract class GameDecorator extends Game implements Serializable {

@Delegate
@Inject
Game game;

/**
*
*/
private static final long serialVersionUID = 9155583141751623258L;

// public GameDecorator(@Delegate @Any Game game) {
// }

@Override
public int getNumber() {
return 98;
}
}

bean.xml

<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" bean-discovery-mode="all">
<decorators>
<class>org.jboss.weld.environment.se.example.numberguess.GameDecorator</class>
</decorators>
</beans>

最佳答案

这是一个老问题,但由于我刚刚遇到了同样的问题,所以让我回答一下。

看来类层次结构中需要存在一个接口(interface)。只需尝试从您的 Game 类中提取一个接口(interface),并使您的 Game'ish 类和 GameDecorator 都实现它。 Weld 文档说:

A decorator is a bean (possibly even an abstract class) that implements the type it decorates and is annotated @Decorator.

关于JAVA - WELD 装饰器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32659243/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com