0

I have below structure

ProjectA

Public Interface A{
Void do something();
}

Now in another class

Class Example{
@Autowired
A objectA;

public void doinSomething(){
objectA.doSomething();//Line of error

}
}

Now this whole project is packaged in Jar and is injected in another project ProjecB.

ProjectB has Code like this:

Class AImpl implemnets A
{
public void doSomething()
{
// Logic of Interface A from ProjectA
}
}
Class Main{

public void doSomethingOfA{
Example example = new Example();
example.doingSomething()
}

}

When i run the code i gett NPE at Line of error as object of AImpl is not injected . Please suggest me how to achieve this reverse hook using spring.

AnkushSeth
  • 55
  • 2
  • 11
  • can you put in the bean definition of A in the projectB where you're trying to use it? If you're missing that then that's where your problem is. – Manish Karki Aug 31 '20 at 16:07
  • Use a constructor argument instead of `@Autowired` fields and you'll usually immediately see what needs to be done. – chrylis -cautiouslyoptimistic- Aug 31 '20 at 16:08
  • 2
    Does this answer your question? [How to autowire a component in a dependency/external jar in Spring?](https://stackoverflow.com/questions/56589896/how-to-autowire-a-component-in-a-dependency-external-jar-in-spring) – Philip Wrage Aug 31 '20 at 16:11

0 Answers0