I have a spring boot application, in that my @Autowire is not working in some situations.
@RestController
public class Check {
@Autowired
SettlementFinanceRepo sfr;
@RequestMapping("/api/checker")
public String checkSettlementFinance(String id) {
SettlementFinanceEntity sfe=new SettlementFinanceEntity();
String status="success";
try {
sfe.setTransaction_id(id);
sfr.save(sfe);
}catch(Exception e) {
e.printStackTrace();
status=e.getMessage();
}
return status;
}
}
The above code is working completely fine, when i call it the REST way http://localhost:8080/api/checker?id=99999 my autowired repo can able to save it into the database.
But when i call this method, from another @RestController class, @Autowired SettlementFinanceRepo sfr getting null
Example:
@RestController
public class SomeRestClass{
Check c=new Check();
public void letsSave(){
c.checkSettlementFinance("99999");
}
}
In this case, my @Autowired SettlementFinanceRepo sfr from Check class is getting null, can someone explain what im missing here...
Thanks!