Skip to content

Commit 201d16c

Browse files
committed
reference type injection
1 parent 18c0861 commit 201d16c

File tree

9 files changed

+147
-1
lines changed

9 files changed

+147
-1
lines changed
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.springcore1.refenceInjection;
2+
3+
public class A {
4+
private int x ;
5+
private B objB;
6+
@Override
7+
public String toString() {
8+
return "A [x=" + x + ", objB=" + objB + "]";
9+
}
10+
public A() {
11+
super();
12+
// TODO Auto-generated constructor stub
13+
}
14+
public A(int x, B objB) {
15+
super();
16+
this.x = x;
17+
this.objB = objB;
18+
}
19+
public int getX() {
20+
return x;
21+
}
22+
public void setX(int x) {
23+
this.x = x;
24+
}
25+
public B getObjB() {
26+
return objB;
27+
}
28+
public void setObjB(B objB) {
29+
this.objB = objB;
30+
}
31+
}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.springcore1.refenceInjection;
2+
3+
import org.springframework.context.ApplicationContext;
4+
import org.springframework.context.support.ClassPathXmlApplicationContext;
5+
6+
public class App {
7+
public static void main(String[] args) {
8+
9+
10+
ApplicationContext context= new ClassPathXmlApplicationContext("com/springcore1/refenceInjection/refconfig.xml");
11+
A objA =(A)context.getBean("aref");
12+
System.out.println(objA);
13+
System.out.println("------------------------");
14+
System.out.println("x = "+ objA.getX());
15+
System.out.println("y = "+objA.getObjB().getY());
16+
System.out.println("objb= "+objA.getObjB());
17+
}
18+
19+
}
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.springcore1.refenceInjection;
2+
3+
public class B {
4+
private int y;
5+
6+
public int getY() {
7+
return y;
8+
}
9+
10+
public void setY(int y) {
11+
this.y = y;
12+
}
13+
14+
public B() {
15+
super();
16+
// TODO Auto-generated constructor stub
17+
}
18+
19+
public B(int y) {
20+
super();
21+
this.y = y;
22+
}
23+
24+
@Override
25+
public String toString() {
26+
return "B [y=" + y + "]";
27+
}
28+
29+
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:context="http://www.springframework.org/schema/context"
5+
xmlns:p="http://www.springframework.org/schema/p"
6+
xsi:schemaLocation="http://www.springframework.org/schema/beans
7+
http://www.springframework.org/schema/beans/spring-beans.xsd
8+
http://www.springframework.org/schema/context
9+
http://www.springframework.org/schema/context/spring-context.xsd" >
10+
11+
12+
13+
<bean class="com.springcore1.refenceInjection.B" name="bref" >
14+
<property name="y" value="2222" />
15+
</bean>
16+
17+
18+
<!-- <bean class="com.springcore1.refenceInjection.A" name="aref">
19+
<property name="x" value="111" />
20+
<property name="ob">
21+
<ref bean="bref"/>
22+
</property>
23+
</bean> -->
24+
<bean class="com.springcore1.refenceInjection.A" name="aref">
25+
<property name="x" value="111" />
26+
<property name="objB"> <ref bean="bref"/>
27+
</property>
28+
</bean>
29+
30+
31+
32+
33+
</beans>

Diff for: target/classes/META-INF/maven/com.springcore/springcore/pom.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#Generated by Maven Integration for Eclipse
2-
#Sat Aug 10 01:03:27 IST 2024
2+
#Mon Aug 12 03:13:41 IST 2024
33
artifactId=springcore
44
groupId=com.springcore
55
m2e.projectLocation=/Volumes/project/LearningSpring/springcore1
1.3 KB
Binary file not shown.
1.5 KB
Binary file not shown.
886 Bytes
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:context="http://www.springframework.org/schema/context"
5+
xmlns:p="http://www.springframework.org/schema/p"
6+
xsi:schemaLocation="http://www.springframework.org/schema/beans
7+
http://www.springframework.org/schema/beans/spring-beans.xsd
8+
http://www.springframework.org/schema/context
9+
http://www.springframework.org/schema/context/spring-context.xsd" >
10+
11+
12+
13+
<bean class="com.springcore1.refenceInjection.B" name="bref" >
14+
<property name="y" value="2222" />
15+
</bean>
16+
17+
18+
<!-- <bean class="com.springcore1.refenceInjection.A" name="aref">
19+
<property name="x" value="111" />
20+
<property name="ob">
21+
<ref bean="bref"/>
22+
</property>
23+
</bean> -->
24+
<bean class="com.springcore1.refenceInjection.A" name="aref">
25+
<property name="x" value="111" />
26+
<property name="objB"> <ref bean="bref"/>
27+
</property>
28+
</bean>
29+
30+
31+
32+
33+
</beans>

0 commit comments

Comments
 (0)