0

I have created an AccountPanel class that is using another class UserClientApi to call some microservices to process information about customers.

@Component
public class AccountPanel {

    private static final int notificationTime = 5000;

    @Autowired
    private UserClientApi  api;
    ...
    }

    @Component
    public class UserClientApi  {

    @Value("${user.api.url}")
    String apiUrl;

    @Autowired
    RestTemplate rest;

    @Override
    public Reader findUserByName(String name) {
     ...
    }
    ...
  }

First I had problems with autowiring RestTemplate, until I added a bean that creates it. Now I am having problems with injecting UserClientApi. I tried 2 dozens of suggestions but still my api variable is always null. I tried extracting interface, added component scan, etc. Nothing is working. Can someone help me? I am using spring-boot 2.7.4 with JDK 14

markalex
  • 8,623
  • 2
  • 7
  • 32
Gary Greenberg
  • 468
  • 1
  • 9
  • 22
  • How did you instantiate AccountPanel? – Stultuske Oct 20 '22 at 06:34
  • does the `UserClientApi` needed to be the inner class of `AccountPanel` ? if not then create another class for `UserClientApi` if yes then try this https://stackoverflow.com/questions/24213823/anyway-to-inject-autowire-an-inner-class-into-an-outer-class – Aleson Oct 20 '22 at 06:39
  • @Aleson it isn't an inner class, the closing bracket is right before the UserClientApi class – Stultuske Oct 20 '22 at 06:48
  • by the code you showed here it looks like the `UserClientApi` is the inner class of `AccountPanel` try create new java file for the `UserClientApi` class – Aleson Oct 20 '22 at 06:51
  • @Aleson by the code the OP showed, it doesn't look like the UserClientApi is an inner class. I've already pointed out there is a closing bracket for AccountPanel before the configuration of UserClientApi – Stultuske Oct 20 '22 at 08:40

0 Answers0