在父抽象类中注入名为component的会话作用域是否存在问题?
这是设置: 我有一个界面:
@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE })
public @interface CurrentTeacher { }
我用它来制作当前学生(在会话范围内):
@Named
@SessionScoped
public class CurrentStudentBean implements Serializable {
@Produces
@Named("currentTeacher")
@currentTeacher
public Teacher getCurrentTeacher() {
//...
return currentTeacher;
}
}
我按顺序注入它的相当混乱的部分。
page.xhtml-> UserBean.java
page.xhtml:
<p:commandButton action="userBean.deleteSubject()" value="delete" />
包含删除主题的操作。
@Named
@ConversationScoped
public class StudentBean.java extends BaseBean {
@Inject
StudentService studentService;
}
public abstract class BaseBean {
@Inject
@CurrentTeacher
private Teacher currentTeacher; //injection OK
public void deleteSubject() {
getService().deleteSubject();
//returns studentService from UserBean and calls BaseService.deleteSubject();
}
}
@Stateless
@LocalBean
public class StudentService extends BaseService {
}
public abstract class BaseService {
@Inject
@CurrentTeacher
private Teacher currentTeacher; //injection FAILED, currentTeacher always null
public void deleteSubject() {
if(currentTeacher != null) { //do something }
}
public Student getTeacher() {
return currentTeacher;
}
}