无法访问CDI



我有一个类,它包含一个带@PostConstruct注释的方法,用于获取客户列表

@ViewScoped
@Named
public class CustomerController extends AlertResponse {
@PostConstruct
public List<Customer> init() {
ResponseEntity<List<Customer>> listResponse =
restTemplate.exchange("http://localhost:8030/api/customers/listCustomers",
HttpMethod.GET, null, new ParameterizedTypeReference<>() {
});
customersList = listResponse.getBody();
return customersList;
}

当我运行应用程序时,我得到这个错误

java.lang.IllegalStateException: Unable to access CDI
at javax.enterprise.inject.spi.CDI.current(CDI.java:65)
at com.sun.faces.cdi.CdiUtils.createDataModel(CdiUtils.java:308)
at com.sun.faces.facelets.component.UIRepeat.getDataModel(UIRepeat.java:255)
at com.sun.faces.facelets.component.UIRepeat.setIndex(UIRepeat.java:465)
at com.sun.faces.facelets.component.UIRepeat.process(UIRepeat.java:515)
at com.sun.faces.facelets.component.UIRepeat.encodeChildren(UIRepeat.java:1081)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1648)
at org.primefaces.component.column.Column.renderChildren(Column.java:90)
at org.primefaces.component.datatable.DataTableRenderer.encodeCell(DataTableRenderer.java:1356)
at org.primefaces.component.datatable.DataTableRenderer.encodeRow(DataTableRenderer.java:1272)
at org.primefaces.component.datatable.DataTableRenderer.encodeRows(DataTableRenderer.java:1179)
at org.primefaces.component.datatable.DataTableRenderer.encodeTbody(DataTableRenderer.java:1119)
at org.primefaces.component.datatable.DataTableRenderer.encodeTbody(DataTableRenderer.java:1072)
at org.primefaces.component.datatable.DataTableRenderer.encodeRegularTable(DataTableRenderer.java:401)
at org.primefaces.component.datatable.DataTableRenderer.encodeMarkup(DataTableRenderer.java:331)
at org.primefaces.component.datatable.DataTableRenderer.render(DataTableRenderer.java:106)
at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:97)

当我删除这些行时,视图被渲染得很好

<p:column headerText="Customer Status" sortBy="#{customer.customerStatus}"
filterBy="#{customer.customerStatus}">
<ui:repeat value="#{customer}" var="data">
<h:outputText rendered="#{data.customerStatus == 'Unlocked'}">
<p:tag styleClass="p-mr-2" severity="success" value="UnLocked"
rounded="true"/>
</h:outputText>
<h:outputText rendered="#{data.customerStatus == 'Locked'}">
<p:tag styleClass="p-mr-2" severity="danger" value="Locked"
rounded="true"/>
</h:outputText>
</ui:repeat>
</p:column>

有什么问题吗提前谢谢你

@PostConstruct用于初始化目的,例如打开数据库连接。带@PostConstruct注释的方法必须有void返回类型和无参数:

void init() { ...

相关内容

  • 没有找到相关文章

最新更新