File: context.xml
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
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) {
BeanFactory factory = new XmlBeanFactory(new ClassPathResource(
"context.xml"));
ConstructorConfusionDemo cc = (ConstructorConfusionDemo) factory
.getBean("constructorConfusion");
System.out.println(cc);
}
}
class ConstructorConfusionDemo {
private String someValue;
public ConstructorConfusionDemo(String someValue) {
System.out.println("ConstructorConfusionDemo(String) called");
this.someValue = someValue;
}
public ConstructorConfusionDemo(int someValue) {
System.out.println("ConstructorConfusionDemo(int) called");
this.someValue = "Number: " + Integer.toString(someValue);
}
public String toString() {
return someValue;
}
}
Spring-ConstructorConfusionDemo.zip( 2,599 k)