본문 바로가기
Spring

환경변수 선언하기 - Spring

by GoodDev 2018. 9. 12.

1. PropertyPlaceholderConfigurer 사용

   가. servelet-context.xml

  <!-- properties file -->

<beans:bean id="PropertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

<beans:property name="locations">

<beans:list>

<beans:value>/WEB-INF/spring/config/config.properties</beans:value>

</beans:list>

</beans:property>

<beans:property name="fileEncoding" value="UTF-8" />

</beans:bean>


나 . config.properties

API = http://localhost


다. java class

   @Value("${API}")

    private String api;



2. util:property 사용

가. context.xml

상단 beans 에

xsi:schemaLocation="http://www.springframework.org/schema/util 

http://www.springframework.org/schema/util/spring-util-3.2.xsd"

추가 해줄것.


<util:properties id="defaultValue" location="/WEB-INF/spring/config/config.properties"/>


나. config.perperties 

API = http://localhost


다. java class

   @Value("#{defaultValue['API']}")

    private String api;

댓글