A document has been updated: http://cocoon.zones.apache.org/daisy/documentation/1310.html
Document ID: 1310 Branch: main Language: default Name: Property Handling (unchanged) Document Type: Cocoon Document (unchanged) Updated on: 1/11/07 8:52:40 AM Updated by: Carsten Ziegeler A new version has been created, state: publish Parts ===== Content ------- This part has been updated. Mime type: text/xml (unchanged) File name: (unchanged) Size: 4914 bytes (previous version: 10710 bytes) Content diff: <html> <body> --- <h1>The Cocoon Spring Configurator</h1> --- --- <p>The Spring Configurator is a useful component providing support in common --- configuration issues when using the Spring framework. Although this product has --- been developed inside the Cocoon project, it is aimed at making easier the usage --- of Spring in each and every web application; it is not tied to the famous Cocoon --- web application framework and can be used standalone. The impact on your code is --- nearly zero and the Spring Configurator as only Spring itself as a dependency. --- </p> --- --- <h2>Motivation</h2> --- --- <p>When using a framework like Spring there are always the same problems to --- solve, like</p> --- --- <ul> --- <li>Where do I store my bean configurations?</li> --- <li>How can I parameterize them dynamically?</li> --- <li>Where do I store these extra information?</li> --- <li>How can I handle different environments like a testing environment, a --- development environment and a production environment?</li> --- <li>How can I distribute not only code but also corresponding configurations? --- </li> --- <li>How can I distribute partial web applications?</li> --- <li>How do I manage hierarchial web application contexts?</li> --- </ul> --- --- <p>Of course Spring is flexible enough to enable solutions to the above --- problems, but you have to do it and implement it for your solution. And there is --- more than one way of doing this and each and every project ends up developing --- its own "proprietary" solution. A best practice and a standardized way of doing --- these things would be great. And guess what, the Spring Configurator is the --- answer to your problems. Like Maven has standardized the build process, the --- Spring Configurator standardizes the way of dealing with various configuration --- issues with Spring. Ok, enough motivation, let's see what the Spring --- configurator can provide for your work.</p> --- --- <h2>Requirements</h2> --- --- <p>The Spring Configurator requires</p> --- --- <ul> --- <li>the Spring Framework Version 2.0.1 (or above)</li> --- <li>JDK 1.4 (or above)</li> --- <li>Servlet API 2.3 (or above)</li> --- </ul> --- --- <p>The Spring Configuration requires two additional jar files, the Cocoon --- Configuration API and the Cocoon Spring Configurator, which you can either --- download here or from a public Maven repository by adding the Spring --- Configurator as a dependency to your project:</p> --- --- <p><strong>TODO - Show dependency configuration</strong></p> --- --- <h2>Configuration</h2> --- --- <p>The Spring Configurator uses the Spring the --- <a href="http://static.springframework.org/spring/docs/2.0.x/reference/new-in-2.html#new-in-2-ioc-custom-configuration">extensible --- XML authoring features</a> and therefore it can be directly used in your Spring --- bean configurations. Usually you add the configurator to your global web --- application context configuration (which is usually located at --- <em>/WEB-INF/applicationContext.xml</em>). The extensible XML authoring requires --- that you use the schema based configuration for Spring. Just add the required --- namespace definition, a reference to the configurator XML schema to your bean --- configuration:</p> --- --- <pre><beans xmlns="http://www.springframework.org/schema/beans" --- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" --- <strong>xmlns:configurator="http://cocoon.apache.org/schame/configurator"</strong> --- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd --- <strong>http://cocoon.apache.org/schema/configurator http://cocoon.apache.org/schema/configurator/cocoon-configurator-1.0.xsd"</strong>> --- ... --- </beans> --- </pre> --- --- <p>Then you can initialize the configurator by adding the <tt>settings</tt> --- element to your bean configuration:</p> --- --- <pre> <!-- Activate Cocoon Spring Configurator --> --- <configurator:settings/> --- </pre> --- --- <p>And then...</p> --- --- <h2>Running Modes</h2> --- --- <p>The configurator provides the support of <em>running modes</em>. A running --- mode defines the environment the application is currently running in. For --- example this can be during development, a test setup or production. As you will --- see in just some paragraphs, the configurator can use different configurations --- and settings depending on the running mode.</p> --- --- <p>A running mode is just a unique text key, like <tt>dev</tt>, <tt>test</tt> --- or <tt>prod</tt>. This key is used to determine the correct configuration at --- runtime. Although you can use any text key, it is advisable to use one of the --- standard keys (dev, test or prod).</p> --- --- <p>The running mode can be set in two ways: you can either set it in your --- <tt>applicationContext.xml</tt> as a configuration for the <tt>settings --- </tt>element:</p> --- --- <pre> <!-- Activate Cocoon Spring Configurator --> --- <configurator:settings runningMode="test"/> --- </pre> --- --- <p>Or you can define the running mode by setting the system property --- <tt>org.apache.cocoon.mode</tt> on startup of your web application, usually you --- do this by specifying <tt>-Dorg.apache.cocoon.mode=test</tt> when starting your --- application server. The system property has precedence over the value from the --- application context. The default running mode is <tt>prod</tt>.</p> --- --- <h2>Property Configurations</h2> --- <p>For using properties in your configuration files, Spring provides the <a href="http://static.springframework.org/spring/docs/2.0.x/reference/beans.html#beans-factory-placeholderconfigurer">property placeholder configurer</a> which you have to configure in your application (79 equal lines skipped) implementation.</li> </ul> --- <h2>Configuring Log4j</h2> --- --- <p>You can use the Configurator to --- configure <a href="http://logging.apache.org/log4j/">Log4j</a> through an XML --- configuration file:</p> --- --- <pre> <bean name="org.apache.cocoon.spring.configurator.log4j" --- class="org.apache.cocoon.spring.configurator.log4j.Log4JConfigurator" --- scope="singleton"> --- <property name="resource" value="/WEB-INF/cocoon/log4j.xconf"/> --- </bean> --- </pre> --- --- <p>The property <tt>resource</tt> should point to a valid Log4j XML --- configuration file. You can use all properties configured through the --- Configurator in the XML configuration and reference the actual values.</p> --- </body> </html>