Spring注解@Autowired如何工作? [英] How does Spring annotation @Autowired work?

查看:135
本文介绍了Spring注解@Autowired如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了@Autowired的示例:

public class EmpManager {
   @Autowired
   private EmpDao empDao;
}

我很好奇empDao如何获取设置,因为没有设置方法,而且它是私有的.

I was curious about how the empDao get sets since there are no setter methods and it is private.

推荐答案

Java允许通过编程简单问题.

Java allows access controls on a field or method to be turned off (yes, there's a security check to pass first) via the AccessibleObject.setAccessible() method which is part of the reflection framework (both Field and Method inherit from AccessibleObject). Once the field can be discovered and written to, it's pretty trivial to do the rest of it; merely a Simple Matter Of Programming.

这篇关于Spring注解@Autowired如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆