【问题标题】:JAVA - WELD Decorator errorJAVA - 焊接装饰器错误
【发布时间】:2015-09-18 19:00:29
【问题描述】:

我尝试在焊接中制作装饰器,但焊接返回错误。我不明白我的错误是什么。我使用了相同的焊接示例 "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>

【问题讨论】:

  • 可以添加游戏类型的装饰豆吗?

标签: java decorator weld


【解决方案1】:

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

似乎需要在类层次结构中存在一个接口。只需尝试从您的 Game 类中提取一个接口,并使您的 Game'ish 类和 GameDecorator 都实现它。 焊接文件说:

装饰器是一个 bean(甚至可能是一个抽象类),它 实现了它所装饰的类型并被注解为@Decorator。

【讨论】:

    猜你喜欢
    • 2013-06-08
    • 1970-01-01
    • 1970-01-01
    • 2010-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-08
    相关资源
    最近更新 更多