I am new to Spring. Please clarify this doubt. In Spring, using annotation autowiring, private variables can be accessed (i.e. while creating a bean, annotation autowiring is used to set value to an attribute of an object, even if it is declared as private). Does it not violates Java's encapsulation (i.e Information hiding)?
Here, I have declared the constructor as private because i dont want anybody creating object for this class from outside. But through annotation autowiring Spring can create an object which breaks by intention. Please clarify this,.. I may be wrong in understanding... Does it mean through annotation we can break Java's encapsulation?
Not really the concept of encapsulation is more towards the clients that will use your code to do some business logic. these clients cannot access your private members so your encapsulation is preserved.
technical frameworks like spring hibernate will access your private member for technical initialisation only, they are not client of your business api.
I hope that makes sense to you