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

Commitcdda6c2

Browse files
Spring constructor based DI
1 parent9e5e748 commitcdda6c2

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
packagespring_constructor_based_di;
2+
3+
/**This one is also working fine.
4+
* But in order to make this one work, I'll have to enable
5+
* constructor-based DI in beans.xml and comment out other two DI methods in the TextEditor
6+
* and SpellChecker beans.*/
7+
importorg.springframework.context.support.AbstractApplicationContext;
8+
importorg.springframework.context.support.ClassPathXmlApplicationContext;
9+
10+
importcommon.TextEditor;
11+
12+
publicclassMainAppDemoConstructorBasedDI {
13+
publicstaticvoidmain(String[]args) {
14+
AbstractApplicationContextcontext =newClassPathXmlApplicationContext(
15+
"spring_constructor_based_di/beansForDemoConstructorBasedDI.xml");
16+
17+
TextEditorte = (TextEditor)context.getBean("textEditor");
18+
19+
te.spellCheck();
20+
context.registerShutdownHook();
21+
22+
System.out.println("Program ends.");
23+
}
24+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<beansxmlns="http://www.springframework.org/schema/beans"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://www.springframework.org/schema/beans
6+
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
7+
8+
<beanid="textEditor"class="common.TextEditor"lazy-init="true">
9+
<constructor-argref="spellChecker"/><!-- this is constructor based dependency injection-->
10+
</bean>
11+
<beanid="spellChecker"class="common.SpellChecker"lazy-init="true"></bean>
12+
13+
</beans>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp