,我了解到,我们可以在一个私有字段使用Spring的@Autowired注解来完成自动注射, @Autowired可以在许多条件下使用,如Spring如何实现该技术?今天
@AutoWired
public void setInstrument(Instrument instrument){
this.instrument = instrument;
}
,但我们也可以把@AutoWired
,这样
@AutoWired
private Instrument instrument;
我想知道,怎么可能春天注入的对象为私人领域,我知道我们可以使用Java的反射来获取一些元数据,当我使用反射来设置对象的私有字段,这里出现了一个问题,以下是堆栈跟踪
java.lang.IllegalAccessException: Class com.wire.with.annotation.Main can not access a member of class com.wire.with.annotation.Performer with modifiers "private"
有的身体可以解释吗?为什么春天可以注入一个对象到私人领域而没有setter方法。非常感谢
反射,BCEL等。 – zeroke
它是'@ Autowired'。 –