“@inject”-ed 属性保持空
2022-09-03 14:31:09
我正在尝试将服务注入我的Bean中,但它始终是.我收到以下错误:WELD-001000 解析属性 userBean 时针对基值 null 时出错。null
一些代码片段:
索引.xhtml
<h:body>
Hello from Facelets
#{userBean.name}
</h:body>
用户豆.java
package beans;
import Domain.User;
import java.io.Serializable;
import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;
import service.UserService;
@Named
@SessionScoped
public class UserBean implements Serializable{
@Inject UserService service;
private User user;
public UserBean(){
this.user = service.find_user("foo");
}
public String getName(){
return "bar";
}
}
用户服务.java
package service;
import Domain.User;
import javax.ejb.Stateless;
import javax.inject.Named;
@Named
@Stateless
public class UserService {
public UserService(){}
public User find_user(String name){
return new User();
}
}