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

Spring Beans Configuration Example

The document outlines a Spring application configuration using XML, defining dependencies for 'spring-core' and 'spring-context'. It includes a 'beans.xml' file that specifies two beans: 'Order' and 'Customer', with lifecycle methods for 'Order'. The main application class demonstrates the creation and management of these beans using the Spring IoC container.

Uploaded by

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

Spring Beans Configuration Example

The document outlines a Spring application configuration using XML, defining dependencies for 'spring-core' and 'spring-context'. It includes a 'beans.xml' file that specifies two beans: 'Order' and 'Customer', with lifecycle methods for 'Order'. The main application class demonstrates the creation and management of these beans using the Spring IoC container.

Uploaded by

Suresh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

<dependencies>

<dependency>
<groupId>[Link]</groupId>
<artifactId>spring-core</artifactId>
<version>[Link]</version>
</dependency>

<dependency>
<groupId>[Link]</groupId>
<artifactId>spring-context</artifactId>
<version>[Link]</version>
</dependency>

</dependencies>

===[Link]

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


<beans xmlns="[Link]
xmlns:xsi="[Link]
xmlns:context="[Link]
xsi:schemaLocation="[Link]
[Link]
[Link]
[Link]
default-lazy-init="true">

<bean id="o" class="[Link]" init-method="start" destroy-


method="stop" scope="prototype">
</bean>

<bean id="c" class="[Link]">


</bean>
</beans>

package [Link];
public class Customer {
String name;
String email;
public Customer(){

}
public Customer(String name, String email) {
[Link] = name;
[Link] = email;
}
@Override
public String toString() {
return "Customer [name=" + name + ", email=" + email + "]";
}
}

package [Link];

public class Order {

Integer id;
Double amount;
public Order(){

}
@Override
public String toString() {
return "Order [id=" + id + ", amount=" + amount + "]";
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
[Link] = id;
}
public Double getAmount() {
return amount;
}
public void setAmount(Double amount) {
[Link] = amount;
}
public void start() {
[Link](" bean ready to use ,created ");
}
public void stop() {
[Link](" bean ready to stop ");

package [Link].springapp1;

import [Link];
import [Link];
import [Link];
import [Link];
public class App
{
public static void main( String[] args )
{ //IOC container - create beans, destroying, lifecycle, scope

// BeanFactory ioc=new XMLBeanFactory(new


FileSystemResource("[Link]"));
ClassPathXmlApplicationContext ioc = new ClassPathXmlApplicationContext(
"[Link]");
//object creation,destruction ,lifecycle, scope
Order o=(Order)[Link]("o");
Order o1=(Order)[Link]("o");
Order o2=(Order)[Link]("o");
[Link]([Link]() +" "+[Link]() +" "+ [Link]());
[Link](9999.99);
[Link](102);
[Link]([Link]()+" "+[Link]());
Customer c=(Customer)[Link]("c");
[Link](c);
[Link]();
}
}

You might also like