15,000 Jobs Available in:
Java, ASP, C#, PHP, SQL, SAP, MySQL and many more.
- Class Quick -
The moose likes Spring and the fly likes wiring in Spring Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Application Frameworks » Spring
Reply Bookmark "wiring in Spring" Watch "wiring in Spring" New topic
Author

wiring in Spring

prateek sharmaa
Greenhorn

Joined: May 15, 2010
Posts: 29
hi all,
i am new to spring.
so can anyone please guide me to any thread here in java ranch or can explain what does wiring means in Spring?
Sumeet H Singh
Greenhorn

Joined: Jan 03, 2009
Posts: 18
Hi Prateek,
Wiring is the method by which you specify the relationships between various beans in your application i.e. if a bean A is dependent on another bean B, then the method of specifying that relationship is called wiring.

There are probably more that one ways of specifying the wiring mechanism, but I have come across only XML configuration till now..

Consider this example:

You have 2 classes- PrintNoClass & RandomNoGeneratorClass. The first class has the functionality for printing a random no, and its dependent on the second class for getting that no.

In Spring, you define the dependencies like this: (the code in red is where actual "wiring" is taking place)

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

<beans xmlns="http://www.springframework.org/schema/beans"
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-2.0.xsd">

<bean id="randomNoBean" class="com.test.RandomNoGeneratorClass">
<property name="lowerLimit" value="0" />
<property name="upperLimit" value="500" />
</bean>

<bean id="printNoBean" class="com.test.PrintNoClass">
<property name="randomNo" ref="randomNoBean" />
</bean>
</beans>


--
Sumeet
SCJP. SCWCD

This message was edited 1 time. Last update was at by Sumeet H Singh



Sumeet
SCJP, SCWCD
Nisha gowda
Greenhorn

Joined: Feb 23, 2010
Posts: 9
Thanks Sumeet,

Good explanation. Simple terms and demonstrated with example.
 
 
subject: wiring in Spring
 
developer file tools