jon*_*ima 1 java decorator 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)
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
游戏装饰器.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;
}
}
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
小智 5
这是一个老问题,但由于我刚刚遇到了同样的问题,所以让我回答一下。
看来类层次结构中需要存在一个接口。只需尝试从您的 Game 类中提取一个接口,并使您的 Game'ish 类和 GameDecorator 都实现它。焊接文件说:
装饰器是一个 bean(甚至可能是一个抽象类),它实现它所装饰的类型并被注释为 @Decorator。
| 归档时间: |
|
| 查看次数: |
852 次 |
| 最近记录: |