ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • springframework + commons-configuration + jasypt 사용 예
    개발 2015. 1. 31. 17:38
    반응형

    springframework와 연동하여 사용하는 예


    프로퍼티 관련하여서는 org.springframework.beans.factory.config.PropertyPlaceholderConfigurer 클래스를 사용한다. (설명 및 사용 예는 생략)


    jasypt를 이용하여 암호화된 내용을 처리할 때는 EncryptablePropertyPlaceholderConfigurer 클래스를 사용한다.

    (org.jasypt.spring3.properties.EncryptablePropertyPlaceholderConfigurer or org.jasypt.spring31.properties.EncryptablePropertyPlaceholderConfigurer)


    - commons-configuration  maven dependency 추가


    <dependency>

    <groupId>commons-configuration</groupId>

    <artifactId>commons-configuration</artifactId>

    <version>1.10</version>

    <exclusions>

    <exclusion>

    <artifactId>commons-logging</artifactId>

    <groupId>commons-logging</groupId>

    </exclusion>

    </exclusions>

    </dependency>


    - xml 기반 config 사용

    <bean id="xpathExpressEngine" class="org.apache.commons.configuration.tree.xpath.XPathExpressionEngine" />


    - 리로링 전략 적용

    <bean id="configReloadStrategy" class="org.apache.commons.configuration.reloading.FileChangedReloadingStrategy" />


    1. org.springmodules.commons.configuration.CommonsConfigurationFactoryBean 클래스 사용

    maven dependency 추가

    <dependency>

    <groupId>org.springmodules</groupId>

    <artifactId>spring-modules-jakarta-commons</artifactId>

    <version>0.8</version>

    </dependency>


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

    <property name="properties">

    <bean class="org.springmodules.commons.configuration.CommonsConfigurationFactoryBean">

    <property name="configurations">

    <list>

    <ref local="configuration" />

    </list>

    </property>

    </bean>

    </property>

    </bean>


    <bean id="configuration" class="org.apache.commons.configuration.CompositeConfiguration">

    <constructor-arg>

    <list>

    <bean class="org.apache.commons.configuration.PropertiesConfiguration">

    <constructor-arg type="java.lang.String">

    <value>local_config.properties</value>

    </constructor-arg>

    </bean>

    <bean class="org.apache.commons.configuration.XMLConfiguration">

    <constructor-arg type="java.net.URL">

    <value>default_config.xml</value>

    </constructor-arg>

    <property name="reloadingStrategy" ref="configReloadStrategy" />

    <property name="expressionEngine" ref="xpathExpressEngine" />

    </bean>

    </list>

    </constructor-arg>

    </bean>


    2. org.apache.commons.configuration.ConfigurationConverter 클래스 사용

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

    <property name="properties">

    <bean class="org.apache.commons.configuration.ConfigurationConverter" factory-method="getProperties">

    <constructor-arg>

                    <bean class="org.apache.commons.configuration.CompositeConfiguration">

    <constructor-arg>

    <list>

    <bean class="org.apache.commons.configuration.PropertiesConfiguration">

                                <constructor-arg type="java.lang.String">

                                    <value>local_config.properties</value>

                                </constructor-arg>

                            </bean>

                            <bean class="org.apache.commons.configuration.XMLConfiguration">

                                <constructor-arg type="java.lang.String">

                                    <value>default_config.xml</value>

                                </constructor-arg>

    <property name="reloadingStrategy" ref="configReloadStrategy" />

    <property name="expressionEngine" ref="xpathExpressEngine" />

                            </bean>

    </list>

    </constructor-arg>

                           </bean>              

    </constructor-arg>

    </bean>

    </property>

    </bean>


    - XMLConfiguration 혹은 PropertiesConfiguration을 동시에 거의 사용하지는 않을 것같다. (상황에 맞게 선택하면 될듯)


    반응형
Designed by Tistory.