【问题标题】:JSF 2 Injection problem thus application will not deploy to Glassfish serverJSF 2 注入问题,因此应用程序不会部署到 Glassfish 服务器
【发布时间】:2019-10-18 03:46:27
【问题描述】:

我将List<Reception> 注入ReceptionService 类,但我得到的只是一个错误,项目不会部署:我得到的错误是:

Unsatisfied dependencies for type List<Reception> with qualifiers @Default
  at injection point [BackedAnnotatedField] @Inject com.github.adminfaces.starter.service.ReceptionService.selectedPatients
  at com.github.adminfaces.starter.service.ReceptionService.selectedPatients(ReceptionService.java:0)

我已经将 bean-discovery-mode="all" 设置为 beans.xml

List&lt;Reception&gt; selectedPatients 具有其 getter 和 setter 方法的 PatientList

import com.github.adminfaces.starter.model.Reception;
import com.github.adminfaces.starter.service.ReceptionService;
import org.omnifaces.cdi.ViewScoped;

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

@Named
@ViewScoped
public class PatientListMB implements Serializable {


    @Inject
    ReceptionService receptionService;

    Integer id;

    LazyDataModel<Reception> patients;

    Filter<Reception> filter = new Filter<>(new Reception());

    List<Reception> selectedPatients; //patients selected in checkbox column

    List<Reception> filteredValue;// datatable filteredValue attribute (column filters)

我正在注入 List&lt;Reception&gt; selectedPatientsReceptionService

package com.github.adminfaces.starter.service;

import com.github.adminfaces.starter.infra.model.Filter;
import com.github.adminfaces.starter.infra.model.SortOrder;
import com.github.adminfaces.starter.model.Reception;
import com.github.adminfaces.template.exception.BusinessException;

import javax.ejb.Stateless;
import javax.inject.Inject;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import static com.github.adminfaces.template.util.Assert.has;

/**
 * @author rmpestano
 *         Reception Business logic
 */
@Stateless
public class ReceptionService implements Serializable {

    @Inject
    List<Reception> selectedPatients;

【问题讨论】:

  • 请改进您问题中的代码格式等

标签: jsf-2 cdi inject


【解决方案1】:

我想您正在使用admin-starter 作为参考项目,如果您查看代码,您会发现Utils.java 中有一个producer 方法负责创建汽车列表。

将它带到您的项目中,您只需要创建一个返回列表或列表的生产者方法,或者您可以简单地删除 @Inject 并实例化列表并手动添加对象,而不是使用注入。

【讨论】:

  • 问题是我没有创建生产者方法。我添加了一个 UtilsReception 类,现在一切正常。我更喜欢使用注入方法,因为它看起来更有条理。谢谢@rmpestano
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-08-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-10
  • 2020-05-03
相关资源
最近更新 更多