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 .

©2020 ioDraw All rights reserved
Java realization PDF Online preview ( Four methods ) Android Development — Display food information according to customer budget spark.sql.shuffle.partitions and spark.default.parallelism The difference between Big data environment --- data warehouse (hive+mysql+hadoop) The construction of Children programming children's learning route What do you do in Shanghai to make money fast ? this 10 You can have a try ! Advanced programmer - Deep understanding of data structure After the outbreak Which programming has a bright future 2020 Nobel Prize in physiology or medicine announced Trump's "VIP therapy ": Is receiving a drug treatment that has not yet been approved