【问题标题】:WELD-001408: Unsatisfied dependencies for type HttpSessionWELD-001408:HttpSession 类型的依赖项不满足
【发布时间】:2015-12-08 02:01:37
【问题描述】:

我的 JSF 项目中有这个(现在臭名昭著)@SessionScoped bean:

@Named(value = "appointmentFormBean")
@SessionScoped
public class AppointmentFormBean implements Serializable {



 @Inject
    private transient AppointmentService service;

public AppointmentFormBean() {
    bookedAlready = new ArrayList<>();
    types = new LinkedHashMap<>(4, (float) 0.75);
}

public AppointmentService getService() {
    return service;
}

public void setService(AppointmentService service) {
    this.service = service;  

  }
...
//other fields, setters and getters
}

我有以下用于 EJB 的接口:

  @Local
  public interface AppointmentRepository {/**methods*/}

  @Local
  public interface AppointmentService {/**methods*/}

这些是 EJB(简要):

@Singleton
@InMemoryRepository
public class InMemoryAppointmentRepository implements AppointmentRepository {/**code*/}

@Stateless
@Default
public class DefaultAppointmentService implements AppointmentService {

private AppointmentRepository repository;

@Inject
public DefaultAppointmentService(@InMemoryRepository AppointmentRepository repository) {
        this.repository = repository;
    }
...}

在构建期间(否则会成功)我收到以下 WELD 警告:

INFO: WELD-000101: Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
WARN: WELD-000411: Observer method [BackedAnnotatedMethod] org.jglue.cdiunit.in...receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.

在运行期间我得到这个异常:

Severe:   Exception while loading the app : CDI deployment failure:WELD-001408: Unsatisfied dependencies for type HttpSession with qualifiers @CdiUnitServlet
  at injection point [BackedAnnotatedField] @Inject @CdiUnitServlet private org.jglue.cdiunit.ContextController.session
  at org.jglue.cdiunit.ContextController.session(ContextController.java:0)
WELD-001475: The following beans match by type, but none have matching qualifiers:
  - WELD%AbstractSyntheticBean%WEB-INF/lib/cdi-unit-3.1.3%HttpSession

如果您愿意,我可以打印整个堆栈。浏览 stackoverflow 和网络我发现了许多关于可能出错的理论,但不是一个适用的解决方案。有人建议该错误可能是由于 Glassfish 与 Weld 集成、Glassfish 与 Java SE 8 20 之前的集成(我使用的是 jdk-8u65-linux-x64.rpm),但后来我看到人们在运行他们的项目时遇到了类似的问题在 WildFly 上。

所以我叫你来救援:-)

ps 我的项目在这里可用:https://github.com/vasigorc/rimmaproject

【问题讨论】:

    标签: glassfish cdi jboss-weld


    【解决方案1】:

    经过数小时的调查可以解决这个问题。感谢 BrynCooke @此链接:https://github.com/BrynCooke/cdi-unit/issues/58

    问题是我的 cdi-unit maven 依赖项必须在测试范围内。我这样做了,还从我正在使用的 cdi-unit 工件中排除了weld-se-core,并将后者添加为单独的依赖项,但在version supported by Glassfish 4.1中。

    这是 pom.xml 中的 fix-part

       <dependency>
            <groupId>org.jglue.cdi-unit</groupId>
            <artifactId>cdi-unit</artifactId>
            <version>3.1.3</version>
            <exclusions>                
                <exclusion>
                    <groupId>org.jboss.weld.se</groupId>
                    <artifactId>weld-se-core</artifactId>
                </exclusion>
            </exclusions>
            <scope>test</scope>                          
        </dependency>   
        <dependency>
            <groupId>org.jboss.weld.se</groupId>
            <artifactId>weld-se-core</artifactId>
            <version>2.2.2.Final</version>
            <scope>test</scope>
        </dependency>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-20
      • 1970-01-01
      • 1970-01-01
      • 2015-02-09
      • 2015-05-08
      • 1970-01-01
      相关资源
      最近更新 更多