Sie sind auf Seite 1von 1

Setter Injection For Primitive Type Dependency Example

Step1:Creating
Step2:Adding
Right
Select
Download
Click
Project
NEW->Java
Jars
OnJars
Spring
Name
Project
Project
to
&Click
Project
Project
Folder
On -->
Finish
in Select
Eclipse.Build Path -->Select Configure Build Pa
th --->Select Libraries Tab -->Select Add Exteral Jar ->Select Jars from Downloa
d }Locations
Step3:Creating
package
import
public
Step4:Configuring
<?xml
<beans
xsi:schemaLocation="
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="1.0"
java.util.List;
java.util.Set;
class
xmlns="http://www.springframework.org/schema/beans"
com.app;
private
public
}@Override
http://www.springframework.org/schema/beans
super();
this.empId
this.details
this.marks
return
Employe
Bean
Employe()
int
List<String>
Set<String>
void
String
intThe
List<String>
Set<String>
getEmpId()
empId;
details;
marks;
"Employe
Class(Create
empId;
setEmpId(int
setDetails(List<String>
+setMarks(Set<String>
encoding="UTF-8"?>
{XML
toString()
",
= marks="
{File
=empId;
marks;
details;
getMarks()
marks;
getDetails()
[empId="
details;
{ +{empId)
Java
marks
+{class)
empId
{+marks)
{ "]";
details)
+ ",{ details="
http://www.springframework.o
{
+ details
rg/schema/beans/spring-beans.xsd">
Step5:Creating
</beans>
package
import
public
<!--class
<bean
</bean>
public
org.springframework.context.ApplicationContext;
org.springframework.context.support.ClassPathXmlApplicationContext;
<property
</property>
com.app;
bean
ApplicationContext
class="com.app.Employe"
static
<list>
</list>
<set>
</set>
Test
definitions
Main
<value>C</value>
<value>B</value>
<value>A</value>
name="empId"
name="details">
{name="marks">
void
Program(Test)
main(String[]
herecontext=new
-->name="empobj">
value="101"
args)ClassPathXmlApplicationContext("config.
{/>
}xml"); //Employe
System.out.println(emp);
Employe
}
emp=context.getBean("empobj",Employe.class);
emp=(Employe)context.getBean("empobj");

Das könnte Ihnen auch gefallen