Common Configuration

Anyframe Core를 사용하여 개발할 때 필수적으로 필요한 설정 정보들이 있다. Anyframe Core에서 제공하는 테크니컬 서비스들이 사용하는 메시지들과 Anyframe Core에서 확장한 Spring 속성 정의 파일에 사용되는 태그에 대한 정의가 공통적으로 필요하다.

Anyframe MessageSource

Anyframe Core의 테크니컬 서비스들 중 Properties, Id Generation, Query 서비스에서 자체적으로 사용하는 메시지들을 공통 MessageSource에 설정해줘야 한다. 이 테크니컬 서비스들을 사용하여 개발할 때 유용한 정보 메시지나 분명한 에러 메시지를 제공함으로써 서비스 활용도를 높여준다.

보다 자세한 MessageSource 내용에 대해서는 본 매뉴얼의 Spring >> IoC >> Extensions >> MessageSource를 활용한 국제화(I18N) 지원 을 참고하도록 한다.

Samples

다음은 Anyframe Core 사용 시 작성하는 MessageSource 속성 설정에 대한 예제이다.
  • Configuration
  • 다음은 Anyframe Core의 테크니컬 서비스들 중 Properties, Id Generation, Query 서비스에서 사용하는 메시지 Properties 파일(properties.properties, idgeneration.properties, query.properties)을 정의해놓은 것이다. 실제 각 Properties 파일은 각 서비스 라이브러리(JAR) 파일내에 존재한다.
    <bean class="org.springframework.context.support.ResourceBundleMessageSource"
        id="messageSource">
        <property name="basenames">
          <list>
            <value>anyframe/core/properties/messages/properties</value>
            <value>anyframe/core/idgen/messages/idgeneration</value>
            <value>anyframe/core/query/messages/query</value>
            <!-- 프로젝트에서 message properties 파일 추가 -->
          </list>
        </property>
    </bean>	
    

Configuration Tag 확장

Anyframe Core의 QueryService 또는 PropertiesService의 속성 정의 XML을 보면, <config:configuration>와 같은 태그를 볼 수 있다. 이는 Anyframe에서 확장한 태그로 anyframe-core-service-2.0.xsd의 구조 정의를 따르고 있다. <config:configuration> 태그를 사용하기 위해서는 ConfigurableCallback 빈을 설정해야 한다.

ConfigurableCallback 빈은 Anyframe Common 라이브러리(anyframe.common-x.x.x.jar)내의 spring.handlers의 정의에 따라, anyframe.common.config.ServiceNamespaceHandler에 의해 처리된다. 그리고 ServiceNamespaceHandler 내의 inner class인 PropertyModifyingBeanDefinitionDecorator에서 ReplaceOverride 인스턴스를 생성하는데 이때, setConfiguration이라는 메소드명과 configurableCallBack 이라는 bean name을 인자로 전달하고 있다.

Spring Container에서 Spring 속성 정의 파일들(context-xxx.xml)을 읽어서 정의된 Bean들의 인스턴스를 생성할 때, ConfigurableCallBack을 통해 <config:configuration>내에 정의된 내용은 org.apache.avalon.framework.configuration.Configuration 객체의 형태로 해당 구현 클래스의 configure() 메소드에 전달되어 해당 서비스의 구현 클래스내에서 Configuration 객체를 이용하여 속성 정보를 읽어 처리할 수 있도록 하고 있다.

즉, 이와 같이 <config:configuration> 태그 정의 부분이 있는 경우, 태그 내부에 작성된 정보들을 Configuration 객체 형태로 해당 구현 클래스의 configure() 메소드에 전달해주기 위해 ConfigurableCallback 정의가 필요하다.

Samples

다음은 Configuration 확장 Tag를 사용하기 위해 설정한 예이다.
  • Configuration
  • 다음은 Anyframe Core에서 확장한 Configuration 확장 Tag를 사용하기 위해서는 반드시 아래와 같이 공통 Spring 속성 정의 파일 내에 configurableCallBack Bean을 설정해야 한다.

    이때 <config:configuration> 태그를 직접 사용하는 Spring 속성 정의 파일에서 <beans> 태그 내에 XML Namespace로 config를 작성하고, SchemaLocation 정보에 anyframe-service-2.0.xsd를 추가해야 함에 유의하도록 한다.
    <bean id="configurableCallBack" 
            scope="prototype" 
            class="anyframe.common.config.ConfigurableCallback"/>
    다음은 <config:configuration> 태그를 사용하는 Anyframe Core의 Properties 서비스 속성 정의 파일의 일부이다. 보다 자세한 Properties 서비스 내용에 대해서는 본 매뉴얼의 Spring >> Tech. Service >> Properties 를 참고하도록 한다.
    <beans xmlns="http://www.springframework.org/schema/beans"
        ...중략
        xmlns:config="http://www.sds.samsung.com/schema/service"
        xsi:schemaLocation="http://www.springframework.org/schema/beans 	                
        ...중략
        http://www.sds.samsung.com/schema/service 
        http://www.sds.samsung.com/schema/service/anyframe-service-2.0.xsd">
    
    <bean name="propertiesService" 
        class="anyframe.core.properties.impl.PropertiesServiceImpl">
        <config:configuration>
          <properties>
               <!-- PAGE -->
               <element key="PAGE_SIZE" value="10"/>
               <element key="PAGE_UNIT" value="10"/>
               ...중략
          </properties>				
        </config:configuration>					
    </bean>
    
    다음은 <config:configuration> 태그를 사용하는 Anyframe Core의 Query 서비스 속성 정의 파일의 일부이다. 보다 자세한 Query 서비스 내용에 대해서는 본 매뉴얼의 Spring >> Tech. Service >> Query 를 참고하도록 한다.
    <beans xmlns="http://www.springframework.org/schema/beans"
        ...중략
        xmlns:config="http://www.sds.samsung.com/schema/service"
        xsi:schemaLocation="http://www.springframework.org/schema/beans 	                
        ...중략
        http://www.sds.samsung.com/schema/service 
        http://www.sds.samsung.com/schema/service/anyframe-service-2.0.xsd">
    
    <bean id="sqlLoader" 
        class="anyframe.core.query.impl.config.loader.SQLLoader">
        <config:configuration>
          <filename>
             classpath:/services/query/mappings/mapping-general-query.xml
          </filename>
          ...중략
        </config:configuration>
    </bean>