本文介绍了WELD-001408:对于具有限定词@Default的Customer类型的不满足的依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个Java EE新手。我想测试JSF,因此做了一个简单的程序,但是不能部署它。我收到以下错误消息:

 不能部署onlineshop-war 
部署失败=部署期间发生错误:异常在加载应用程序时:CDI部署失败:WELD-001408:注入点的限定符@Default
的不符合依赖关系[BackedAnnotatedField] @Inject private de.java2enterprise.onlineshop.RegisterController.customer
at de .java2enterprise.onlineshop.RegisterController.customer(RegisterController.java:0)
。有关详细信息,请参阅server.log。

我的代码如下:
Customer.java:

  package de.java2enterprise.onlineshop.model; 

public class Customer {
private String email;
private String password;
}

registerController.java:

  package de.java2enterprise.onlineshop; 

import java.io.Serializable;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import javax.inject.Inject;
import de.java2enterprise.onlineshop.model。*;

@Named
@RequestScoped
public class RegisterController {

private static final long serialVersionUID = 1L;

@Inject
私人客户;

public Customer getCustomer(){
return customer;
}

public void setCustomer(Customer customer){
this.customer = customer;
}

public String persist(){
return/index.xhtml;
}
}

为编译它,我不得不包含cdi-api。 jar作为外部库。任何人谁可以帮助我?谢谢所有提前。

解决方案

您的客户类必须被CDI发现为豆。为此,您有两个选择:


  1. 将。由于 @Model 是一个刻板印象,所以它是这样的伎俩。一个限定符,如 @Named 不是定义注释的bean,为什么它不起作用的原因


  2. 将您的bean归档中的 bean发现模式从默认的已注释更改为all通过在您的jar中添加一个 beans.xml 文件。


请记住,@Named只有一种用法:将您的bean暴露给UI。其他用途是用于不良做法或与旧版框架兼容。


I'm a Java EE-newbie. I want to test JSF and therefore made a simple program but can not deploy it. I get the following error message:

cannot Deploy onlineshop-war
deploy is failing=Error occurred during deployment: Exception while loading the app : CDI deployment failure:WELD-001408: Unsatisfied dependencies for type Customer with qualifiers @Default
at injection point [BackedAnnotatedField] @Inject private de.java2enterprise.onlineshop.RegisterController.customer
at de.java2enterprise.onlineshop.RegisterController.customer(RegisterController.java:0)
. Please see server.log for more details.

My code is as follows:Customer.java:

package de.java2enterprise.onlineshop.model;

public class Customer {
    private String email;
    private String password;
}

registerController.java:

package de.java2enterprise.onlineshop;

import java.io.Serializable;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import javax.inject.Inject;
import de.java2enterprise.onlineshop.model.*;

@Named
@RequestScoped
public class RegisterController {

    private static final long serialVersionUID = 1L;

    @Inject
    private Customer customer;

    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    public String persist() {
        return "/index.xhtml";
    }
}

For compiling it I had to include cdi-api.jar as an external library. Anyone here who could help me? Thank you all in advance.

解决方案

Your Customer class has to be discovered by CDI as a bean. For that you have two options:

  1. Put a bean defining annotation on it. As @Model is a stereotype it's why it does the trick. A qualifier like @Named is not a bean defining annotation, reason why it doesn't work

  2. Change the bean discovery mode in your bean archive from the default "annotated" to "all" by adding a beans.xml file in your jar.

Keep in mind that @Named has only one usage : expose your bean to the UI. Other usages are for bad practice or compatibility with legacy framework.

这篇关于WELD-001408:对于具有限定词@Default的Customer类型的不满足的依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 23:17