1.整体思路
1.拿到运行时对象
2.拿到类中的所有属性值3.判断属性值上面是否有自定义的autowired注解
4.获取属性对应的类
5.实例化对象
6.通过反射给运行时对象的属性赋值
2.自定义注解
@Retention(value = RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Autowired {
}
3.整体实现
public class UserService {
}
public class UserController {
@Autowired
private UserService userService;
public UserService getUserService() {
return userService;
}
public void setUserService(UserService userService) {
this.userService = userService;
}
}
public class ReflectAutowiredImplements {
@Test
public void test() throws IllegalAccessException, InstantiationException {
//Class<UserController> controllerClass = UserController.class;
//1.拿到运行时对象
UserController userController = ne