Spring 속성 주입 set 방법 주입 기본 데이터 형식
1804 단어 J2EE
1. 속성 주입 이 필요 한 클래스
package com.maty.property;
/**
* @author maty e-mail:[email protected]
* @version :2018 5 16 3:04:58
*
*/
public class User
{
private String name; //
// set
public void setName(String name)
{
this.name = name;
}
//
public void UserTest()
{
System.out.println("user name ="+name);
}
}
2. ApplicationContext. xml 의 작성
// : User Spring , property User
3. 주입 이 성 공 했 는 지 테스트 클래스 를 작성 합 니 다.
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.maty.property.PropertyConstructor;
import com.maty.property.User;
/**
* @author maty e-mail:[email protected]
* @version :2018 5 16 12:23:01
*
*/
public class MyTest
{
public static void main(String[] args)
{
// : xml
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
User bean = (User) context.getBean("user");
bean.UserTest();
}
}
4. 실행 결과
log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
user name =maty
5. 총화
속성 주입 기능 은 주로 bean 태그 의 property 하위 태그 에 있 으 며, 이 하위 태그 작업 의 전 제 는 속성 주입 이 필요 한 클래스 가 이 속성의 set 방법 을 제공 하 는 것 입 니 다.주입 대상 이 라면 다음 편 을 참고 하 세 요.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
layui- 동적 렌더링 드롭다운 상자 (백그라운드에서 드롭다운 상자 값 가져오기) & 드롭다운 상자 기본 선택 설정동적 렌더 드롭다운 상자 드롭다운 상자 기본 선택 설정...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.