[英]CDI bean with Application Scope doesn't recognize name of the Session Bean
我在默认构造函数的AllUsersBean类中遇到错误。 它在此行中无法识别subBean users.add(subBean.clone()); 我正在使用subBi.clone将用户提交的信息克隆到称为用户的UsersList中。 感谢您的任何建议。
这是错误的:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-
compile) on project Test: Compilation failure
[ERROR] ......(here was path to this class) AllUsersBean.java:[25,18] cannot find symbol
[ERROR] symbol: variable subBean
为了解决该问题,我尝试在UserBean类中为appBean添加getter和setter,但是它不起作用。
package testpkg;
/*Importing required java libraries */
import javax.inject.Named;
import javax.enterprise.context.ApplicationScoped;
import java.util.ArrayList;
import java.util.List;
@Named("appBean")
@ApplicationScoped
public class AllUsersBean {
private List<UserBean> users;
public AllUsersBean(){
users = new ArrayList<UserBean>();
users.add(subBean.clone());
}
public List<UserBean> getUsers() {
return users;
}
public void setUsers(List<UserBean> users) {
this.users = users;
}
}
package testpkg;
/*Importing required java libraries */
import java.io.Serializable;
import javax.inject.Named;
import javax.inject.Inject;
import javax.enterprise.context.SessionScoped;
@Named("subBean")
@SessionScoped
public class UserBean implements Serializable{
private String fname;
@Inject
private AllUsersBean appBean;
public UserBean() {
this.fname = null;
}
public String getFname() {
return fname;
}
public void setFname(String fname) {
this.fname = fname;
}
public AllUsersBean getAppbean() {
return appBean;
}
public void setAppbean(AllUsersBean appBean) {
this.appBean =appBean;
}
}
您是否尝试过创建名称为AllUsersBean的subBean的字段,并使用带有@PostConstruct批注的方法进行初始化? 通常,使用克隆不是一个好习惯
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.