Appearance
因为反射。
普通:
new UserService();
框架:
Class clazz; clazz.newInstance();
扫描Class
↓
获取Class对象
反射实例化
保存Bean
Class<?> clazz = Class.forName( "com.demo.UserService" ); Object bean = clazz.getDeclaredConstructor() .newInstance();
Spring Boot启动时,会自动完成大量Bean创建。