.properties 의 경우 ISO-8859-1 문자셋이기때문에 한글 사용에 문제가 있어, IDE Tool 을 사용하여 자동으로 변환하는 방법을 이용하곤 했다.

하지만 이 방법의 경우에도 서버상에 올라가있는 설정 파일을 확인 및 직접 수정할 경우 에로 사항이 발생한다.

또한 개개인별 .properties 를 ms949, euc-kr 등으로 변경 해 놓는 사태도 발생해버린다. OTL...


이러한 불편함을 해결 하기 위해 .xml 확장자를 이용하면 좋을것이다.



[applicationContext.xml]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<!--?xml version="1.0" encoding="UTF-8"?-->
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:/properties/globals-properties.xml</value>
            </list>
        </property>
    </bean>
 
    <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource ">
        <property name="basenames">
            <list>
                <value>classpath:properties/messages-properties</value>
            </list>
        </property>
    </bean>
 
    <util:properties id="global" location="classpath:/properties/globals-properties.xml">
    <bean id="globalsProperties" class="pe.kr.ddakker.core.framework.web.GlobalsProperties">
        <constructor-arg index="0">
            <ref bean="global">
        </ref></constructor-arg>
    </bean>
<beans>
</beans></util:properties></beans>


[Sample.java]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
@Controller
public class Sample {
     
    @Value("#{global['server.type']}") private String serverType;
    @Resource GlobalsProperties globalsProperties;
 
    @RequestMapping(value="/sample")
    public void test(ModelMap model) {
        // Properties Case 1
        System.out.println("serverType: " + serverType);
 
        // Properties Case 2
        System.out.println("server.type: " + globalsProperties.getProperty("server.type"));
             
        //MessageSource Case 1
        System.out.println("msg.test1: " + messageSource.getMessage("msg.test1", null, Locale.getDefault()));
 
        // MessageSource Case 2
        System.out.println("msg.test2: " + messageSource.getMessage("msg.test2", new String[]{"첫번째", "두번째"}, Locale.getDefault()));
    }
}


[sample.jsp]

1
2
3
4
5
6
7
8
9
10
11
12
13
    <!-- Properties Case 1 -->
    <spring:eval expression="@global['server.type']">
    <spring:eval var="serverType" expression="@global['server.type']">
    <c:if test="${ serverType == 'local' }">
        로컬임
    </c:if>
 
    <!-- MessageSource Case 1 -->
    <spring:message code="msg.test1">
 
    <!-- MessageSource Case 2 -->
    <spring:message code="msg.test2" arguments="첫번째, 두번째">
</spring:message></spring:message></spring:eval></spring:eval>


globals-properties.xml

1
2
3
4
5
6
7
8
9
<!--?xml version="1.0" encoding="UTF-8" ?-->
 
<properties>
    <comment>globals-properties local</comment>
    <entry key="server.type">local</entry>                              <!-- 서버정보[local,dev,stage,real] -->
 
    <entry key="content.key.result.code">result</entry>                 <!-- 결과 코드 Key -->
    <entry key="content.key.result.message">message</entry>             <!-- 결과 메시지 Key -->
</properties>


[messages-properties_ko.xml]

1
2
3
4
5
6
7
8
9
<!--?xml version="1.0" encoding="UTF-8" ?-->
 
<properties>
    <comment>messages-properties_ko</comment>
 
 
    <entry key="msg.test1">ko 한글 정보는...</entry>
    <entry key="msg.test2">ko 파라미터1 = {0}, 파라미터2 = {1}...</entry>
</properties>


+ Recent posts