반응형



context-properties.xml 설정


예를 들어 이처럼 자주사용하는 페이지사이즈나, 페이지유닛, return되는 Url 을 변경할때 변경된 모든 곳을 하나씩 변경할 필요없이 

애초에 xml 설정으로 해당 key값을 호출하여 넣어주면된다.

아래는 xml 설정이다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
 
    <bean name="propertiesService" class="egovframework.rte.fdl.property.impl.EgovPropertyServiceImpl" destroy-method="destroy">
        <property name="properties">
            <map>
                <entry key="pageUnit" value="10"/>
                <entry key="pageSize" value="10"/>
                <entry key="returnUrl" value="http://127.0.0.1:7070"/>
            </map>
        </property>
    </bean>
    
</beans>    
 
cs




아래는 해당 xml을 호출하는 방법이다.

컨트롤러 상단에 service 등, 공통되게 필요한 변수 선언하는 곳에 위의 xml에서 name을 정해준 값을 통해 호출한다.


1
2
@Resource(name="propertiesService")
protected EgovPropertyService propertiesService;
cs


그리고 사용하고 싶은 메소드 부분에 아래의 코드를 입력하면 해당 변수에 propertiesService의 key에 해당하는 value값이 들어간다.


1
2
3
String pageUnit = propertiesService.getString("pageUnit");
String pageSize propertiesService.getString("pageSize");
String returnUrl= propertiesService.getString("returnUrl");
cs


반응형

+ Recent posts