1. jdbc.prperties 파일
스프링 jdbc.properties파일의 속성 값
jdbc.url= url
jdbc.username= name
jdbc.password= passwd
2. context.xml 파일
스프링 context.xml에 아래 태그 util:properties를 추가하고 id, location(properties파일 경로)입력한다.
<util:properties id="getId" location="/WEB-INF/spring/jdbc.properties"/>
util:properties를 사용하기 위해서 context.xml <beans xmlns 태그에 줄쳐진 부분을 추가한다.
---------------------------------------------------------------------------------------------------------------------------
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-4.0.xsd">
3. GetValue.java 파일
Java 스프링 어너테이션을 이용한 속성 값을 요청 @Value("#{id['key']}")
public class GetValue{
@Value("#{ getId['jdbc.url']}")
private String url;
@Value("#{ getId['jdbc. username']}")
private String name;
@Value("#{ getId['jdbc. password']}")
private String passwd;
}
※ 스프링 @Value의 경우 정적(static) 속성은 지원하지 않는다.
해당 부분을 처리 하기위해서는 Java setter를 사용하는 방법이 있다.