mik*_*128 36 jsf dependency-injection java-ee cdi managed-bean
我是Java EE新手.我想测试JSF,因此制作了一个简单的程序,但无法部署它.我收到以下错误消息:
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.
Run Code Online (Sandbox Code Playgroud)
我的代码如下:Customer.java:
package de.java2enterprise.onlineshop.model;
public class Customer {
private String email;
private String password;
}
Run Code Online (Sandbox Code Playgroud)
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";
}
}
Run Code Online (Sandbox Code Playgroud)
为了编译它,我必须包含cdi-api.jar作为外部库.谁在这里可以帮助我?谢谢大家.
Ant*_*and 58
你的Customer课必须被CDI发现为一个bean.为此你有两个选择:
在其上放置一个定义注释的bean.这@Model是一种刻板印象,这就是为什么它会成功的原因.像这样的限定符@Named不是定义注释的bean,这是它不起作用的原因
通过在jar中添加文件,将bean归档中的bean发现模式从默认的"annotated"更改为"all" beans.xml.
请记住@Named只有一个用法:将bean暴露给UI.其他用法是针对不良实践或与遗留框架的兼容性.
确保您拥有正确的进口也是一件好事
我遇到了这样的问题,我发现 bean 正在使用
javax.faces.view.ViewScoped;
^
Run Code Online (Sandbox Code Playgroud)
代替
javax.faces.bean.ViewScoped;
^
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
88754 次 |
| 最近记录: |