,我瞭解到,我們可以在一個私有字段使用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'。 –