時候我已經注射了AdminService的顯示java.lang.NullPointerException出現了,雖然我在另一個託管bean注入這個bean與以同樣的方式和一切工作:春天注射顯示java.lang.NullPointerException
@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);
}
}
你可以發佈bean配置嗎? – paary
我發佈了AdminService實現 –
我建議你讓服務有一個訪問它的應用程序bean(你可以直接通過代碼按照使用註釋的順序加載它),然後在你的視圖的每個bean中注入這個bean,以便能夠隨時隨地訪問服務。 –