当我注入了 AdminService 时,出现了 java.lang.NullPointerException ,尽管我以相同的方式在另一个托管 bean 中注入了这个 bean 并且一切正常:
@ManagedBean
@SessionScoped
public class ScheduleController implements Serializable {
/**
*
*/
private static final long serialVersionUID = -1489523494215832724L;
private ScheduleModel eventModel;
@ManagedProperty(value = "#{adminService}")
AdminService adminService;
private ScheduleEvent event = new DefaultScheduleEvent();
public ScheduleController() {
List<Service> = adminService.getAllService();
}
public AdminService getAdminService() {
return adminService;
}
public void setAdminService(AdminService adminService) {
this.adminService = adminService;
}
管理服务实现:
Service("adminService")
public class AdminServiceImpl implements AdminService,Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@Autowired
AdminDao adminDao ;
// adminDao injected by spring
@Transactional
public void add(Admin admin) {
adminDao.save(admin);
}
@Transactional
public void edit(Admin admin) {
adminDao.update(admin);
}
@Transactional
public void delete(Admin admin) {
adminDao.delete(admin);
}
@Transactional
public Admin getAdmin(Integer adminId) {
return adminDao.findById(adminId);
}
@Transactional
public List<Admin> getAllAdmin() {
return adminDao.findAll();
}
/**
* @return the adminDao
*/
public AdminDao getAdminDao() {
return adminDao;
}
/**
* @param adminDao the adminDao to set
*/
public void setAdminDao(AdminDao adminDao) {
this.adminDao = adminDao;
}
@Override
public Admin authenticate(String adminName, String adminPass) {
return this.adminDao.authenticate(adminName, adminPass);
}
}