File: context.xml
"http://www.springframework.org/dtd/spring-beans.dtd">
File: Main.java
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
public class Main {
public static void main(String[] args) throws Exception {
BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("context.xml"));
ConstructorTestBean testBean = (ConstructorTestBean) beanFactory.getBean("testBean");
System.out.println(testBean.isConstructor1Used());
System.out.println(testBean.isConstructor2Used());
}
}
class ConstructorTestBean {
private boolean constructor1Used = false;
private boolean constructor2Used = false;
public ConstructorTestBean(String name, Integer id) {
this.constructor1Used = true;
}
public ConstructorTestBean(String firstName, String lastName) {
this.constructor2Used = true;
}
public boolean isConstructor1Used() {
return this.constructor1Used;
}
public boolean isConstructor2Used() {
return this.constructor2Used;
}
}