Some time ago, there were some irregularities in project scanning , There is a class problem, that is, it cannot be loaded dynamically . So there's another way in the code : Directly from Spring get bean object , And then through the getClass Method to get the class . Project is using Springboot Developed .

  original :
Class<? extends Object> clazz = Class.forName(className);
  Now? :
Object bean = applicationContext.getBean(className); Class<? extends Object>
clazz = bean.getClass();
In the subsequent code test, there are many no bean named 'XXXX' available The problem of , Summarize the problems :

1,className Instead of using full class names such as :com.way.inter.impl.CalImpl, Need to be converted to lowercase class name :calImpl. Because the class is given to spring When managing, the lower case class name is used by default bean Of id;

2, If the class name is all capital letters ,Spring Class names are used directly as id, Therefore, the hump structure must be used for class names , This is conducive to unified processing in the code ;

3,Component Use after annotation value Specify the name , This will also affect bean Access to . for example :@Component(value="CalureImpl");

4, Nonstandard naming of class name , use $ And other special characters ;

5, Directly use the name of the class interface to get the bean, And the interface is not used Component annotation ;

6, Classes with duplicate names in the project also affect bean Access to .

Technology