在父抽象类中注入名为组件的会话范围是否有问题?
这是设置:我有一个界面:
@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;
}
}