undefinedfix
Sign in

Springboot assembles the same class in multiple places

ysfmj edited in Wed, 21 Sep 2022
  • Let's start with the words. In the service layer package, there is an implementation class userweixinserviceimpl, which is implemented in the controller userweixincontroller @ Autowired automatic assembly, testing the easy-to-use, but also in the toolkit (and the controller package is the same level) in a class @ Autowired automatically assembles the implementation class. When it is called, the information printed to the console shows that it is null. Annotation is used on the tool class header @ Component, which is explained in combination with the picture.
  • Look at the figure below, in the controller package com.xdf.wxpad Userweixinserviceimpl is automatically assembled in the userweixincontroller in. Controller through @ Autowired, which is easy to use in browser test.
  • Take a look at the picture below . xdf . wxpad . The class in wxutil is also used in wxutil @ Autowired assembles the same class, and the tool class header uses annotations @ Component。 When a service of type userweixinserviceimpl is used in a method in the tool class, the print is null in the console.
  • Can't you assemble classes of the same type in multiple places like this? Or is my usage wrong? QQ = 409223171
2 Replies
Nahuel
commented on Wed, 21 Sep 2022

The problem has been solved https://segmentfault.com/a/11...

user619229
commented on Thu, 22 Sep 2022

UserService is NULL in WxUtil. It should be called userService in your static method, so the method of using your article is acceptable. AddUser in your article is not a static method. You don't need to add postconstruct and it's not empty