Web/Spring
[Spring] 외부 프로퍼티 파일 읽어오기
개발하는개발자
2021. 3. 26. 14:00
반응형
applicationContext.xml 파일에서 아래와 같이 작성합니다.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context-4.3.xsd">
<context:property-placeholder location="file:///C:\...파일경로\propertiesFileName.properties" />
<bean id="prop" class="com.was.ios.common.util.Properties">
<property name="uploadBasePath" value="${props.uploadBasePath}"/>
<property name="uploadTempPath" value="${props.uploadTempPath}"/>
</bean>
</beans>
<context:property-placeholder location="file:///C:\...파일경로\propertiesFileName.properties" />
위 코드의 역할은 해당 위치에 있는 파일을 읽은 후 <bean id="" class="">에 명시된 class파일에 setter를 이용하여 properties의 데이터를 넣어줍니다.
반응형