0

i am using a springboot application as a dependency in my standalone java application.

I am getting null pointer exception for autowired (bService) class used in utility method.

Main method in parentapplication ---

{
BatchProcessor obj = new BatchProcessor;
obj.getBatchStatus(123);

}

------------------- Spring Boot Ccode ----

public class BatchProcessor {
@Autowire
IBatchService bSerice;
public int getBatchStatus(int batch_id){ return bSerice.getStauts(batch_id);}
}

interface IBatchService {}
@Service
public class CBABatchService implements IbatchService{ public int getStatus(int id){}}
Chandan Gupta
  • 599
  • 3
  • 7
  • 20
  • The annotation `@service` should have the first letter capitalized, `@Service` :) Moreover, to let Spring resolve the dependency from `IBatchService`, you need that the `CBABatchService` is in a package that Spring can scan – riccardo.cardin Aug 27 '20 at 07:33
  • Sorry riccardo.cardin - service is @Service only. my main method is in different application and BtachProcessor is in different sprint boot application which i am using as jar. – Chandan Gupta Aug 27 '20 at 07:39
  • Yep, understand. Does your application use Spring to resolve dependencies? Anyway, if you instantiate the class `BatchProcessor` using the `new` operator directly, there is no way to Spring to kick in :) – riccardo.cardin Aug 27 '20 at 07:44

0 Answers0