Is possible in Spring that class for bean doesn\'t have public constructor but only private ? Will this private constructor invoked when bean is created? Thanks.
Yes, Private constructors are invoked by spring. Consider my code:
Bean definition file:
Bean class:
package com.aa.testp;
public class Message {
private String message;
private Message(String msg) {
// You may add your log or print statements to check execution or invocation
message = msg;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public void display() {
System.out.println(" Hi " + message);
}
}
The above code works fine. Hence, spring invoked the private constructor.