fabric3
Content
Documentation
Developer Reference
Packaging
Packaging For Different Environments
Packaging For Different Environments
search
attachments
weblink
advanced
image-effects
image-attributes
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
Colour picker
More colours
Formatting
Strikethrough
Subscript
Superscript
Monospace
Clear formatting
Bullet list
Numbered list
Task list
Outdent
Indent
Align left
Align center
Align right
Page layout
Link
Table
Insert
Insert content
Files and images
Link
Symbol
Emoticon
Markup
Horizontal rule
Insert macro
User mention
Jira Issue/Filter
Info
Status
Gallery
Table of Contents
Jira timeline
Lucidchart Diagrams
Trello Board
Other macros
Page layout
No layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Find/Replace
Keyboard shortcuts help
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account.
<p>It is often necessary to create application configuration that varies by runtime environment. For example, service endpoint URLs, JMS connection information, and JDBC data source URLs may differ for testing and production environments.</p><p>To satisfy these requirments, Fabric3 provides <em>named environments</em> for composite activation and the ability to define configuration templates for use in a composite file.</p><h2>Named Environments</h2><p>Named environments such as "production", "testing", and "development" can be configured in the runtime systemConfig.xml using the <environment> tag as shown below:</p><table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="xml" data-macro-schema-version="1" style="background-image: url(https://fabric3.atlassian.net/wiki/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6eG1sfQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre><config xmlns="urn:fabric3.org"> <runtime environment="testing"/> </config> </pre></td></tr></table><p>In the above example, the runtime will be booted in the "testing" environment. If no value is specified, the runtime will be booted in the default "production" environment.</p><p>It is possible to control which environments a deployable composite is deployed in via the @environments attribute in sca-contribution.xml:</p><table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="xml" data-macro-schema-version="1" style="background-image: url(https://fabric3.atlassian.net/wiki/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6eG1sfQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre><contribution xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912" xmlns:f3-tests="org.codehaus.fabric3.tests"> <deployable composite="f3-tests:ProductionComposite" environments="production"/> <deployable composite="f3-tests:TestComposite" environments="development test"/> </contribution> </pre></td></tr></table><p>In the above example, <em>ProductionComposite</em> is configured to deploy only when the runtime is booted in the <em>production</em> environment. <em>TestComposite</em>, in contrast, specifies a space-delimited list of environments. Specifically, it will be activated when the runtime is booted in the <em>development</em> or <em>test</em> environment. If no value is specified, the default <em>production</em> value will be used. This means that if an environment is not specified for a runtime in systemConfig.xml and a deployable composite entry does not contain an @environments attribute, the composite will be activated as both values will default to <em>production</em>.</p><h3>Creating Environment-Specific Configuration</h3><p>Using named environments, an application can specify datasource, JNDI, and other resource configuration that is specific to an environment. It is also possible to activate a set of components for a specific environment. To do this, place the resource definitions in a composite or set of composites that are configured to activate in <em>production</em>, <em>testing</em> or some other environment. These composites can then be contained in a single contribution or in an external contribution.</p><h2>Configuration Templates</h2><p>Binding configuration such as endpoint addresses may often change from testing to production. Fabric3 provides a simple templating mechanism whereby this binding information may be substituted at deployment time. The following demonstrates how to use <binding.template> to substitute web service configuration:</p><table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="xml" data-macro-schema-version="1" style="background-image: url(https://fabric3.atlassian.net/wiki/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6eG1sfQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre><component name="TestClient"> <implementation.java class="..."/> <reference name="service"> <binding.template name="TestServiceBinding"/> </reference> </component> </pre></td></tr></table><p>The <binding.template> element instructs the runtime to substitute the specified template when the contribution is installed. The template is defined using the <template> element in a composite:</p><table class="wysiwyg-macro" data-macro-name="code" data-macro-schema-version="1" style="background-image: url(https://fabric3.atlassian.net/wiki/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre><composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912" xmlns:f3="urn:fabric3.org"...> <f3:template name="TestServiceBinding"> <binding.ws uri="http://localhost:8900/TestService"/> </f3:template> </composite> </pre></td></tr></table><p>The template composite can be contained in the same contribution or placed in a different contribution. If it is in the same contribution, the named environments feature described above can be used to activate different template definitions depending on the environment. For example, <em>production</em> and <em>testing</em> template composites can be provided.</p><p>As previously mentioned, it is also possible to place composites containing template definitions in a different contribution. In this case, the contribution containing the template must be installed prior to any contributions containing references to it (Note that the Fabric3 capabilities ordering feature can be used to have the runtime automatically order template and referring contributions).</p><p>By creating a separate contribution containing templates, it is possible to reuse template definitions across applications. For example, multiple applications may reference the same web service or REST endpoints. A standardized contribution containing templates for the endpoints can be reused across those applications. Within that contribution, it is also possible to configure specific templates for production and testing.</p><h3>Specifying Template Definitions in the System Configuration</h3><p>In addition to including template definitions in a contribution, it is also possible to specify them in the controller systemConfig.xml. Note participant runtimes do not need to have template definitions as the information is only used by the controller. The following shows how to specify a template in systemConfig.xml:</p><table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="xml" data-macro-schema-version="1" style="background-image: url(https://fabric3.atlassian.net/wiki/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6eG1sfQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre><config xmlns="urn:fabric3.org" xmlns:f3="urn:fabric3.org" xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912"> <web.server> <http port="8900"/> </web.server> <templates> <template name="SystemConfigTestServiceBinding"> <sca:binding.ws uri="http://localhost:8900/TestService"/> </template> </templates> </config> </pre></td></tr></table><p><strong>Note that namespaces must be used for template configuration</strong></p><h3>Stubbing Binding Templates in Testing</h3><p>Sometimes it is necessary to stub out a binding template for testing. For example, a component may take an optional reference that must be explicitly bound to an external service. The composite containing the component contains a binding template configuration. For testing, the external service is not needed. The binding template can be defined using a blank binding.sca, which will result in no binding being applied to the reference:</p><table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="xml" data-macro-schema-version="1" style="background-image: url(https://fabric3.atlassian.net/wiki/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6eG1sfQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre><config xmlns="urn:fabric3.org" xmlns:f3="urn:fabric3.org" xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912"> <web.server> <http port="8900"/> </web.server> <templates> <template name="SystemConfigTestServiceBinding"> <sca:binding.sca/> </template> </templates> </config> </pre></td></tr></table><h3>JPA/Hibernate Overrides</h3><p>Persistence context configuration can also be specified in an environment-dependent fashion similar to the way templates are. For more details, see <a class="confluence-link" href="/wiki/spaces/FABRIC/pages/524314/Hibernate+and+JPA" data-linked-resource-id="524314" data-linked-resource-version="17" data-linked-resource-type="page" data-linked-resource-default-alias="Hibernate and JPA" data-base-url="https://fabric3.atlassian.net/wiki">Hibernate and JPA</a>.</p>
Save
Close
Edit
Preview
View changes
Revert to last published version
{"serverDuration": 453, "requestCorrelationId": "95f71488cbb04e0fbb77738b9805d672"}