VisualBuilder
  Home > Java > Tutorials > How to create a bean descriptor XML file? - Spring tutorial
Tell a friend
Link to us
Total Members
      Members: 84648
     
Sitemap Forum Chat
Home
Spring Tutorial Tutorial Home
1 . What is Spring?
2 . What are the main concepts for Spring?
3 . Why use Spring?
4 . Spring architecture
5 . Installing Spring
6 . Where is Spring in our applications?
7 . How to create a bean descriptor XML file?
8 . Spring and Struts
9 . Spring and Struts - Hello World example
10 . Spring data access overview
11 . Spring data access example using Hibernate
12 . Next Steps
 
Java Group Home
Java Discussion (273)
Java Members (27593)
Java Resources
Java Source Code (1095)
Java Articles (5)
Java Blogs
Java Jobs
Java Components (84)
Java Books
Java Websites (126)
Java News (103)
Java Q & A (114)
- Java Ask Question
- Java Questions
- Java Unanswered Questions
 
GROUPS
.NET
ASP.NET
.NET
C#
ASP
Visual Basic
Java
Java
JSP
EJB
Other
Delphi
C++
Ajax
UML
JavaScript
PHP
Web Design
Web Hosting
SQL Server
Oracle
Project Management
More Groups

 
LEARNING CENTER
TUTORIALS
.NET
.NET Tutorial
ASP Tutorial
ASP.NET Database Tutorial
ASP.NET Development Tips
ASP.Net Security,Internationalisation And Deployment
ASP.NET Server Controls Tips
ASP.NET Tutorial
C Sharp Tutorial
Web Development
Flex Tutorial
HTML Tutorial
Learn AJAX Tutorial
PHP Tutorial
Software Development
Database Tutorial
SQL Tutorial
UML Tutorial
Java
Ant Tutorial
EJB 3 Tutorial
Hibernate Tutorial
Java Tutorial
Java Web Component Tutorial
Java XML Tutorial
JDBC Tutorial
JDK1.5 Tutorial
JSF Tutorial
JSP And J2EE Design Tutorial
JSP Tutorial
Spring Tutorial
Struts Tutorial

RESOURCES
Q & A (436 )
Source Code (3275 )
Articles (11 )
Components (1589 )
News (888 )
Websites (1207 )

SUBMISSIONS
Submit Article
Submit Website
Submit News
Submit Source Code
Submit Component

COMMUNITY
Members Directory
Discussion Forum
Chat

SITE
About Us
Sitemap
Search
Contact Us
Link To Us
Feedback
Tell a Friend
Partners
Advertise


Java spring Tutorial
 How to create a bean descriptor XML file?
  << Prev: Where is Spring in our applications? Next: Spring and Struts >>

This section will mention to the ways to declare a business service as a bean


Example for registration a service as bean


<beans>
<bean id="greetingService" class="com.visualbuilder.spring.GreetingService"/>
</beans>


In this example,class “com.visualbuilder.spring.GreetingService” is registered in Spring under name "greetingService".


Example for passing values into properties when initialize bean
Service class:


package com.visualbuilder.spring;
public class ExampleBean
{
 private String s;
 private int i;


 public void setStringProperty(String s) { this.s = s; }
 public void setIntegerProperty(int i) { this.i = i; }
}


Bean declaration:


<bean id="exampleBean" class="com.visualbuilder.spring.ExampleBean">
 <property name="stringProperty"><value>Hi!</value></property>
 <property name="integerProperty"><value>1</value></property>
</bean>

Example for passing property value as an another bean
Service class:


package com.visualbuilder.spring;
public class ExampleBean
{
 private AnotherBean beanOne;
 private YetAnotherBean beanTwo;
 
 public void setBeanOne(AnotherBean b) { beanOne = b; }
 public void setBeanTwo(YetAnotherBean b) { beanTwo = b; }
}


In the XML bean descriptor file:

<bean id="exampleBean" class="com.visualbuilder.spring.ExampleBean">
<property name="beanOne"><ref bean="anotherExampleBean"/></property>
<property name="beanTwo"><ref bean="yetAnotherBean"/></property>
</bean>


<bean id="anotherExampleBean" class="eg.AnotherBean"/>
<bean id="yetAnotherBean" class="eg.YetAnotherBean"/>



Example for passing parameter value into constructor:
Service class:

package com.visualbuilder.spring;
public class ExampleBean
{
 private AnotherBean beanOne;
 private YetAnotherBean beanTwo;
 private int i;


 public ExampleBean(AnotherBean b1,YetAnotherBean b2,int i)
 {
  this.beanOne = b1;
  this.beanTwo = b2;
  this.i = i;
 }
}



In the XML bean descriptor file:

<bean id="exampleBean" class="com.visualbuilder.spring.ExampleBean">
<constructor-arg><ref bean="anotherExampleBean"/></constructor-arg>
<constructor-arg><ref bean="yetAnotherBean"/></constructor-arg>
<constructor-arg><value>1</value></constructor-arg>
</bean>


<bean id="anotherExampleBean" class="com.visualbuilder.spring.AnotherBean"/>


<bean id="yetAnotherBean" class="com.visualbuilder.spring.YetAnotherBean"/>








  << Prev: Where is Spring in our applications? Next: Spring and Struts >>
Java Spring Tutorial Home
Give feedback and win a prize.

 
   Printer Friendly
   Email to a friend
   Add to my Favourites    
  Download PDF version
   Report Bad Submissions
   Submit Feedback
 
  Delicious   Digg   Technorati   Blink   Furl   Reddit   Newsvine   Google Click each image to add
this page to each site.
 
 
Welcome Guest Signup
MEMBER'S PANEL
EMAIL
PASSWORD
Forgot your password?
New User? Click Here!
 
Resend Activation Email!
 
SEARCH
 
 
LINKS
MSN
Video Surveillance
VoIP Internettelefonie
Gift to Pakistan
 
ADVERTISEMENT
 
PARTNER LIST

More
 
 
 

Home | Login | About Us | Contact Us | Privacy Policy | Advertising