-
빈
정의 XML
파일에서
property
태그의
value
태그로
값을 지정
-
String으로
값을 읽음
-
Property의 value를 주입받는 빈에서는 setter를 만드셔야 합니다.
오라클자바커뮤니티에서 설립한
오엔제이프로그래밍 실무교육센터
(오라클SQL, 튜닝,
힌트,자바프레임워크, 안드로이드, 아이폰, 닷넷 실무전문 강의)
uapp-context.xml
<?xml
version="1.0"
encoding="UTF-8"?>
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd“>
<description>Example
configuration to get you started.</description>
<bean
name="sample"
class="onj.value.injection.ValueInjectionExam">
<property
name="name">
<value>onj</value>
</property>
<property
name="age">
<value>6</value>
</property>
</bean>
</beans>
u
ValueInjectionExam.java
package
onj.value.injection;
import
org.springframework.context.support.GenericXmlApplicationContext;
public
class
ValueInjectionExam
{
private
String name;
private
String age;
//빈
정의 XML에서
name이라는
Property의
value
값을
주입받음
public
void
setName(String
name) { this.name
= name; }
//빈
정의 XML에서
age라는
Property의
value
값을
주입받음
public
void
setAge(String
age) { this.age
= age; }
public
String toString()
{
return
"Your
name is "
+ name
+ "
age is "
+ age;
}
public
static
void
main(String[] args)
{
GenericXmlApplicationContext
ctx
= new
GenericXmlApplicationContext();
ctx.load("classpath:app-context.xml");
ctx.refresh();
ValueInjectionExam
exam = (ValueInjectionExam)ctx.getBean("sample");
System.out.println(exam);
}
}
[결과]
댓글 없음:
댓글 쓰기