0% found this document useful (0 votes)
27 views1 page

My Java Springs Journal

In spring, IoC (Inversion of Control) means outsourcing the creation and management of objects. The key points are that an app should be configurable to switch contexts without changing code. To implement IoC, you setup beans in an XML file by defining <bean> elements with ids and class attributes. Then you retrieve values from classes by creating a ClassPathXmlApplicationContext object and calling getBean(), passing the bean id and interface name without changing any code.

Uploaded by

Reynaldi Pane
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)
27 views1 page

My Java Springs Journal

In spring, IoC (Inversion of Control) means outsourcing the creation and management of objects. The key points are that an app should be configurable to switch contexts without changing code. To implement IoC, you setup beans in an XML file by defining <bean> elements with ids and class attributes. Then you retrieve values from classes by creating a ClassPathXmlApplicationContext object and calling getBean(), passing the bean id and interface name without changing any code.

Uploaded by

Reynaldi Pane
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/ 1

Spring Inversion of Control

In spring, we’ll often hear about IoC (Inversion of Control). So, what actually the IoC means ?

I found out a definition for it as “The approach of outsorcing the creation and management of the
objects”

The key points : App should be configurable, to switching context without changing the actual
code

Step :

1. Setup the beans :


- Create an xml file (one way to do it)
Create a <bean> key with id and class attributte (e.g : <bean id=”myCoach”
class=”com.reynaldi.springdemo.BaseballCoach”></bean>) , where class value
need to be a fully-qualified name for a Class

2. Retrieve value from the class :


- Create ClasshPathXmlApplicationContext object, will require you to pass the xml
path as a constructor parameter
- Create an object of the interface that get value from get.Bean() method from
ClassPathXmlApplicationContext object. The get.Bean() method will need two
value as arguments, that is the bean id and the interface name (e.g
context.getBean(“myCoach”, Coach.class) where Coach is an interface name

See that you don’t have to change anything inside your code, just need to change the value in
your application context xml file

You might also like