Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit247cf18

Browse files
pure XML DI using Spring
1 parent8e92cd2 commit247cf18

File tree

6 files changed

+129
-0
lines changed

6 files changed

+129
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
packagepureXMLDependencyInjecttionExample;
2+
3+
importlombok.Getter;
4+
importlombok.Setter;
5+
importlombok.ToString;
6+
7+
@ToString
8+
publicclassCareer {
9+
@Getter
10+
@Setter
11+
privateStringjobType;
12+
13+
@Getter
14+
@Setter
15+
privateintjobLevel;
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
packagepureXMLDependencyInjecttionExample;
2+
3+
importlombok.Getter;
4+
importlombok.Setter;
5+
importlombok.ToString;
6+
7+
@ToString
8+
publicclassCity {
9+
@Getter
10+
@Setter
11+
privateStringcityName;
12+
13+
@Getter
14+
@Setter
15+
privateStringarea;
16+
17+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
packagepureXMLDependencyInjecttionExample;
2+
3+
importorg.springframework.context.support.AbstractApplicationContext;
4+
importorg.springframework.context.support.ClassPathXmlApplicationContext;
5+
6+
/**This app is running fine!
7+
* Remember to add apache.commson.logging and spring jars onto your classpath, otherwise the program won't run.
8+
* It helps me understand how @Resource annotation works! Cool!
9+
* Look at this project along with other two:
10+
* SpringPureXMLDependencyInjectionExample
11+
* Spring@RessourceAnnotationExample
12+
* to help me better understand the three possible ways to do DI using Spring.*/
13+
publicclassMainApp {
14+
15+
publicstaticvoidmain(String...args) {
16+
System.out.println("It started!");
17+
AbstractApplicationContextcontext =newClassPathXmlApplicationContext("spring.xml");
18+
Personp =(Person)context.getBean("person");
19+
20+
System.out.println(p.getCity().toString());
21+
System.out.println(p.getWife().toString());
22+
System.out.println(p.getCareer().toString());
23+
}
24+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
packagepureXMLDependencyInjecttionExample;
2+
3+
importlombok.Getter;
4+
importlombok.Setter;
5+
6+
publicclassPerson {
7+
@Getter
8+
@Setter
9+
privateCitycity;
10+
11+
@Getter
12+
@Setter
13+
privateWifewife;
14+
15+
@Getter
16+
@Setter
17+
privateCareercareer;
18+
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
packagepureXMLDependencyInjecttionExample;
2+
3+
importlombok.Getter;
4+
importlombok.Setter;
5+
importlombok.ToString;
6+
7+
@ToString
8+
publicclassWife {
9+
10+
@Getter
11+
@Setter
12+
privateStringname;
13+
14+
@Getter
15+
@Setter
16+
privateStringfaith;
17+
18+
}

‎SpringTutorials/src/spring.xml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beansxmlns="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+
xsi:schemaLocation="http://www.springframework.org/schema/beans
6+
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
7+
http://www.springframework.org/schema/context
8+
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
9+
10+
<beanid="person"class="pureXMLDependencyInjecttionExample.Person">
11+
<propertyname="city"ref="home123"/>
12+
<propertyname="wife"ref="wife"/>
13+
<propertyname="career"ref="careerFuture"/>
14+
</bean>
15+
16+
<beanid="home123"class="pureXMLDependencyInjecttionExample.City">
17+
<propertyname="cityName"value="San Jose"/>
18+
<propertyname="area"value="NorCal"/>
19+
</bean>
20+
21+
<beanid="wife"class="pureXMLDependencyInjecttionExample.Wife">
22+
<propertyname="name"value="Sophie Yan"/>
23+
<propertyname="faith"value="Christian"/>
24+
</bean>
25+
26+
<bean id ="careerCurrent"class="pureXMLDependencyInjecttionExample.Career">
27+
<propertyname="jobType"value="SDE"/>
28+
<propertyname="jobLevel"value="4"/>
29+
</bean>
30+
<beanid="careerFuture"class="pureXMLDependencyInjecttionExample.Career">
31+
<propertyname="jobType"value="SDE"/>
32+
<propertyname="jobLevel"value="5"/>
33+
</bean>
34+
35+
</beans>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp