Source Code : ConstructorCaller In ContextConfig
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
ConstructorCaller In ContextConfig
File: context.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="testBean" class="ConstructorTestBean">
<constructor-arg value="Steven Devijver"/>
<!--
<constructor-arg value="1"/>
-->
<constructor-arg value="1" type="java.lang.Integer"/>
</bean>
</beans>
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;
}
}
Thank with us