0

In my project I am using a utility jar and in utility we have beans autowired.

When I am calling the method of jar it is giving null pointer exception at the place where autowired bean is used.

I tried to add package of jar in component scan of my project but still it is coming null.

below is the class from the jar file in which I a getting error

@Controller
public class UtilityController{

@Autowired
UtilityService utilityService;

public String getEmployeeDetails(String name){

Sting output = utilityService.getDetails(name);
--
--
}

getEmployeeDetails method is the one which I am trying to call from my code and utilityService is coming as null. I have the source code of jar and it is working fine when I am running it separately.

Neeti
  • 377
  • 1
  • 4
  • 16
  • Could you provide your code which is throwing the exception or does u want us to assume it? – VPK Dec 15 '17 at 06:13

1 Answers1

0

For Spring to create the beans you need to annotate the class with @Component, @Service or other annotations. Now in your case the class which you are trying to annotate is in utility jar. You don't have control over that code so you cannot annotate those classes with some spring annotation.

Another way would be to create you class then create the object of that class from utility jar in your own class and then autowire your class.

Rohit
  • 146
  • 1
  • 5