기록 > 기억
properties 파일 읽어서 SP EL로 표현하기 본문
properties 파일 읽어서 SP EL로 표현하기
1. util 태그를 사용하기 위해 spring-util 스키마 선언
<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/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<!-- property configurer -->
<util:properties id="jdbc" location="classpath:properties/jdbc.properties"/>
<util:properties id="upload" location="classpath:properties/upload.properties"/>
</beans>
# jdbc.properties
jdbc.driver=oracle.jdbc.driver.OracleDriver
jdbc.url=jdbc:oracle:thin:@localhost:1521:moviestar
jdbc.username=scott
jdbc.password=tiger
#upload.properties
upload.path=D:/tomcat7/webapps/upload/
위와같이 util:properties만 설정해주면 xml, JAVA , JSP에서 속성값을 가져다 쓸 수 있음.
1. xml 사용
<!-- dataSource -->
<bean id="dataSourceSpied" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="#{jdbc['jdbc.driver']}"/>
<property name="url" value="#{jdbc['jdbc.url']}"/>
<property name="username" value="#{jdbc['jdbc.username']}"/>
<property name="password" value="#{jdbc['jdbc.password']}"/>
</bean>
2. JAVA 사용
@Value("#{upload['upload.path']}")
private String filePath;
3. JSP 사용
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<spring:eval var="uploadPath" expression="@upload['upload.path']"/>
${uploadPath}
'프로그래밍 > Spring' 카테고리의 다른 글
Spring Project 생성하기 (0) | 2017.11.24 |
---|---|
Spring 개발환경 구축하기 (0) | 2017.11.24 |
스프링 MVC 프로젝트 구조 (0) | 2017.06.07 |
Comments