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;
}
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);
}
}