【问题标题】:@Named @Produces getter not recognized with bean-discovery-mode="annotated"bean-discovery-mode="annotated" 无法识别 @Named @Produces getter
【发布时间】:2016-01-03 18:27:29
【问题描述】:

我正在尝试运行“Java EE 7 Development with WildFly”一书的示例。现在我面临以下问题/问题:

TheatreInfo.java:

@Model
public class TheatreInfo {
    ...
    @Produces
    @Named
    public Collection<Seat> getSeats() {
        return Lists.newArrayList(seats);
    }
    ...
}

Seat.java:

@Dependent
@Named
public class Seat {
    ...
    public String getName() {
        return name;
    }
    ...
}

index.xhtml:

<?xml version="1.0" encoding="UTF-8" ?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
    xmlns:f="http://xmlns.jcp.org/jsf/core"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    template="/WEB-INF/templates/default.xhtml">
    <ui:define name="content">

        <h1>TicketBooker Machine</h1>

        <h:form id="reg">

            <h:panelGrid columns="1" border="1" styleClass="smoke">

                <h:dataTable var="_seat" value="#{seats}" rendered="#{not empty seats}" styleClass="simpletablestyle">

                    ...

                </h:dataTable>

            </h:panelGrid>

        </h:form>

    </ui:define>
</ui:composition>

beans.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"
    version="1.1" bean-discovery-mode="all/annotated">
</beans>

这非常有效——我在我的网络浏览器中看到一张座位表——只要我在 beans.xml 中使用 bean-discovery-mode="all"。在 beans.xml 中使用 bean-discovery-mode="annotated" 后,我在浏览器中分别看不到座位表,我看到一个空表,但没有发生错误。

在书中他们使用 bean-discovery-mode="all" 但我更喜欢查看哪些类是托管 bean,哪些不是。要使用 bean-discovery-mode="annotated" 我必须将 @Dependent 添加到某些类,但我无法解决名称生产者方法的问题。有人可以帮忙吗?

【问题讨论】:

标签: jsf cdi producer


【解决方案1】:

嗯,如果我使用它就会运行

@Named
@RequestScoped
public class TheatreInfo {
...

插入

@Model
public class TheatreInfo {
...

不明白为什么@Named 和@RequestScoped 包含在@Model 原型中!?有人知道吗?

谢谢,多米尼克

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多