How does @Autowired
annotation work for a private field without a getter and a setter?
How can spring access a private field?
It works with reflection. Here you can find an example of how to set public fields. But setting private fields does not make much of a difference
The only difference with a private field is that you will need to set the setAccessible before you are able to read/write to the field. Further, this method can throw a SecurityException. Java Docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With