i have created a simple java class in spring boot application. calling a method ns.mesage(); from two different methods but one is executed and another one throw an null pointer exception.
package TestPackage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/*
import TestPackage.MorningService;
import TestPackage.NightService;*/
@RestController
public class GenerateMessage {
@Autowired
public MorningService ms;
@Autowired
public NightService ns;
@RequestMapping(path = "/test")
public String starter(){
GenerateMessage gm=new GenerateMessage();
ns.mesage(); // this call working fine
gm.mes();
return "Mail scheduled.";
}
public void mes(){
try{
System.out.println("starts2..............");
ns.mesage(); // throwing an exception
}catch(Exception e){
e.printStackTrace();
}
}
}