0% found this document useful (0 votes)
5 views3 pages

Spring Example

The document consists of Java classes for a Person and Certi, along with a Spring application context configuration. The Person class has attributes for name, ID, and a Certi object, while the Certi class holds a name. The App class initializes the Spring context and retrieves a Person bean, displaying its details using the overridden toString method.

Uploaded by

donaldna44
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Spring Example

The document consists of Java classes for a Person and Certi, along with a Spring application context configuration. The Person class has attributes for name, ID, and a Certi object, while the Certi class holds a name. The App class initializes the Spring context and retrieves a Person bean, displaying its details using the overridden toString method.

Uploaded by

donaldna44
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Person.

java

public class Person


{
private String personName;
private int personId;
private Certi certi;

public Person(String name,int id,Certi certi)


{
this.personName=name;
this.personId=id;
this.certi=certi;
}

@Override
public String toString() {
return this.personName + ":"+ this.personId +
":"+this.certi;
}

Certi.java

public class Certi


{
private String name;

public Certi(String name) {


super();
this.name = name;
}

public Certi() {
super();

@Override
public String toString() {
return this.name;
}

App.java

import
org.springframework.context.ApplicationContext;
import
org.springframework.context.support.ClassPathXmlAppli
cationContext;

public class Test {

public static void main(String[] args) {


ApplicationContext context = new
ClassPathXmlApplicationContext("com/spring/constructo
r/ciconfig.xml");
Person p = (Person) context.getBean("per");
System.out.println(p);

}}

Config.xml

<?xml version="1.0" encoding="UTF-8"?>


<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:c="http://www.springframework.org/schema/c"

xsi:schemaLocation="http://www.springframework.org/sc
hema/beans
http://www.springframework.org/schema/beans/spring-
beans.xsd">

<bean name="cer"
class="com.spring.constructor.Certi" c:name="java
full stack">

</bean>
<bean name="per"
class="com.spring.constructor.Person">

<!-- <constructor-arg>
<value>Ram</value>
</constructor-arg>

<constructor-arg>
<value>1234</value>
</constructor-arg>-->

<constructor-arg value="Shyam"/>
<constructor-arg value="101" type="int"/>
<constructor-arg ref="cer"/>

</bean>

</beans>

You might also like