Error description:
There was an unexpected error (type=Internal Server Error, status=500).
Cannot invoke "com.example.produits.service.StabiliteService.saveStabilite(com.example.produits.entities.Stabilite)" because "this.stabiliteService" is null
java.lang.NullPointerException: Cannot invoke "com.example.produits.service.StabiliteService.saveStabilite(com.example.produits.entities.Stabilite)" because "this.stabiliteService" is null
controller class
@Controller
public class StabiliteController {
@Autowired(required = false)
private StabiliteService stabiliteService;
@RequestMapping("/createStabilite")
public String createStabilite(ModelMap modelMap) {
modelMap.addAttribute("stabilite", new Stabilite());
modelMap.addAttribute("mode", "new");
return "formStabilite";
}
@RequestMapping("/saveStabilite")
public String saveStabilite(@Valid Stabilite stabilite, BindingResult bindingResult) {
if (bindingResult.hasErrors())
return "formStabilite";
stabiliteService.saveStabilite(stabilite);
return "formStabilite";
}
service class:
@Service
public interface StabiliteService {
Stabilite saveStabilite(Stabilite s);
Stabilite updateStabilite(Stabilite s);
void deleteStabilite(Stabilite s);
void deleteStabiliteById(Long id);
Stabilite getStabilite(Long id);
List<Stabilite> getAllStabilites();
List<Stabilite> findByLibelleStabilite(String libelle);
Page<Stabilite> getAllStabillitesParPage(int page, int size);
}