[Switch] spring document configuration properties

Spring

1.DTD

 

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN""http://www.springframework.org/dtd/spring-beans-2.0.dtd">

  

The above is the standard DTD of Spring 2.0. In contrast, I don't like to use schema xsd file-style definitions. A lot of them are too long. Schema is only used when you really want to use Spring-defined schemas such as TX and AOP.

 

2.default-lazy-init

 

     Spring's lazy-init can greatly speed up unit testing and integration testing, but pay attention to some classes such as the definition of WebService exported by XFire, and the xx-servlet.xml file of Spring MVC, which cannot be set as lay-init , otherwise it will suffer a lot.

 

 

3.PropertyOverrideConfigurer

   

Unlike PropertyPlaceholderConfigurer which replaces the variables in the context file, PropertyOverrideConfigurer forcibly replaces some properties of some beans with the values ​​in its properties file at the end of ApplicationContext initialization.

    For example, the jdbc connection as Oracle is defined in jdbc.properties of the production environment, and is set to <bean id="dataSource"> through PlaceholderConfigurer, and the following applicationContex-test.xml file is loaded during the test to transparently convert the Configuration changed to Embedded Database.

 

applicationContext-test.xml:  defines the loaded properties.

 

<bean id="testPropertyConfigurer" class="org.springframework.beans.factory.config.PropertyOverrideConfigurer">
        <property name="location" value="classpath:spring/test/jdbc.properties"/>
</bean>

 

 

spring/test/jdbc.properties : Change the url property of the bean whose id is dataSource in the ApplicationContext to use hsqldb.

 

dataSource.url=jdbc:hsqldb:res:default-db

 

4. Spring 2.0 schema shorthand

 

 Spring 2.0 began to promote a series of shorthand, from the rigid <bean id="xx" class="xxxx.xxx.xxx">, to the form of <aop:xxxx>.

 See Appendix A of the Reference Manual for a complete list of schemas: http://www.redsaga.com/spring_ref/2.0/html/xsd-config.html 

 In addition, Appendix B also provides a way to develop your own schema. The manual claims that it is a bit troublesome for ordinary application project teams to develop schemas, but calls on all open source project teams to develop their own schemas to jointly simplify configuration files.

 One of the default schemas that is probably the easiest to use is p, which further simplifies the way the <propertity> node is written.

 

<bean>
  <property name="foo" value="foovalue">
  <property name="fooBean" ref="fooBean"/>
</bean>

<!-- abbreviated as -->
<bean p:foo="foovalue" p:fooBean-ref="fooBean"/> 

 

5.default-merge

 

   Beginning with Spring 2.0M2, beans support the definition of default-merge= "true"  , and subclasses do not need to redefine what has been defined in the parent class's List property. Under the declarative transaction system, a baseTxService base class is generally defined

 

<bean id="baseTxService"
          class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
          abstract="true">
        <property name="transactionManager" ref="transactionManager"/>
        <property name="proxyTargetClass" value="true"/>
   <property name="transactionAttributes">
            <props>
                <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
                <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
                <prop key="save*">PROPAGATION_REQUIRED</prop>
                <prop key="update*">PROPAGATION_REQUIRED</prop>
                <prop key="remove*">PROPAGATION_REQUIRED</prop>
            </props>
        </property>
 </bean>

  

You can define default-merge= true in beans, or define each bean, then the transactionAttributes of the subclass only need to define the new part of the subclass, and there is no need to define get*, save*, etc.

   However, Spring 2.0 has adopted the new AOP writing method, and the importance of this method has decreased.

<beans default-merge="true">
 <bean id="orderManager" parent="baseTxService">
        <property name="target">
            <bean class="org.springside.bookstore.service.OrderManager"/>
        </property>
        <property name="transactionAttributes">
            <props>
                <prop key="shipOrder">PROPAGATION_REQUIRED</prop>
            </props>
         </property>
    </bean>

</beans>

 6.IMPORT

 

     How to organize the ApplicationContext file determines whether declarative programming will turn into configuration hell . SpringSide recommends: For unit testing, the ApplicationContext file should be placed in the ClassPath instead of the WEB-INF directory. Use <Import> whenever possible to help organize ApplicationContext files in modules. For example, /applicationContext.xml and springmvc-servlet.xml in the root directory only define some common things, and then include the applicationContext in the module as follows:

 

<import resource="classpath:org/springside/bookstore/admin/applicationContext-manager.xml"/>

 

7.IntrospectorCleanupListener

 

  Avoid Struts, Quartz's memory leak causes ClassLoader to fail to load. See Spring's API DOC documentation for details :

 

   <listener>
        <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
    </listener>

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326768162&siteId=291194637