Sync docs from master to gh-pages
This commit is contained in:
@@ -568,7 +568,7 @@ table.CodeRay td.code>pre{padding:0}
|
||||
</div>
|
||||
<div id="footer">
|
||||
<div id="footer-text">
|
||||
Last updated 2015-07-31 13:10:25 CDT
|
||||
Last updated 2015-07-31 13:55:44 CDT
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
@@ -588,7 +588,7 @@ table.CodeRay td.code>pre{padding:0}
|
||||
</div>
|
||||
<div id="footer">
|
||||
<div id="footer-text">
|
||||
Last updated 2015-07-31 13:11:03 CDT
|
||||
Last updated 2015-07-31 13:55:44 CDT
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
@@ -636,7 +636,7 @@ spring.cloud.database: mysql://user:pass@host:1234/dbname</code></pre>
|
||||
</div>
|
||||
<div id="footer">
|
||||
<div id="footer-text">
|
||||
Last updated 2015-07-31 13:10:56 CDT
|
||||
Last updated 2015-07-31 13:55:44 CDT
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
@@ -698,7 +698,7 @@ table.CodeRay td.code>pre{padding:0}
|
||||
</div>
|
||||
<div id="footer">
|
||||
<div id="footer-text">
|
||||
Last updated 2015-07-31 13:10:02 CDT
|
||||
Last updated 2015-07-31 13:55:44 CDT
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
@@ -506,10 +506,10 @@ table.CodeRay td.code>pre{padding:0}
|
||||
<div id="toc" class="toc">
|
||||
<div id="toctitle">Table of Contents</div>
|
||||
<ul class="sectlevel1">
|
||||
<li><a href="#_connecting_to_a_cloud">Connecting to a cloud</a></li>
|
||||
<li><a href="#_adding_cloud_connectors">Adding cloud connectors</a></li>
|
||||
<li><a href="#_adding_service_discovery">Adding service discovery</a></li>
|
||||
<li><a href="#_adding_service_connectors">Adding service connectors</a></li>
|
||||
<li><a href="#_connecting_to_a_cloud">Connecting to a Cloud</a></li>
|
||||
<li><a href="#_adding_cloud_connectors">Adding Cloud Connectors</a></li>
|
||||
<li><a href="#_adding_service_discovery">Adding Service Discovery</a></li>
|
||||
<li><a href="#_adding_service_connectors">Adding Service Connectors</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@@ -517,18 +517,15 @@ table.CodeRay td.code>pre{padding:0}
|
||||
<div id="preamble">
|
||||
<div class="sectionbody">
|
||||
<div id="spring-cloud-connectors-install" class="paragraph">
|
||||
<p>This core library provides programmatic access to application and service information. This library has no Spring dependencies and may be used in non-Spring applications.</p>
|
||||
<p>This core library provides programmatic access to application and service information. It has no Spring dependencies and may be used in non-Spring applications.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>This library requires Java 6 or newer.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>This library is cloud-agnostic. Using Java SPI, it supports pluggable cloud and service connectors; support for Cloud Foundry and Heroku is available out-of-the-box, in addition to locally-provided configuration for development and testing.</p>
|
||||
<p><strong>This library requires Java 6 or newer.</strong> It is cloud-agnostic, supports pluggable cloud and service connectors using Java SPI, and provides support for Cloud Foundry and Heroku out-of-the-box, with locally-provided configuration available for development and testing.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect1">
|
||||
<h2 id="_connecting_to_a_cloud">Connecting to a cloud</h2>
|
||||
<h2 id="_connecting_to_a_cloud">Connecting to a Cloud</h2>
|
||||
<div class="sectionbody">
|
||||
<div class="admonitionblock note">
|
||||
<table>
|
||||
@@ -547,20 +544,16 @@ table.CodeRay td.code>pre{padding:0}
|
||||
<div class="ulist">
|
||||
<ul>
|
||||
<li>
|
||||
<p>Include the desired cloud connectors on the runtime classpath <a href="spring-cloud-connectors.html">as described in the main documentation</a>.</p>
|
||||
<p>Include the desired cloud connectors on the runtime classpath, <a href="spring-cloud-connectors.html">as described in the main documentation</a>.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>Create a <code>CloudFactory</code> instance. Creation of a <code>CloudFactory</code> instance is a bit expensive, so using a singleton instance is recommended. If you are using a dependency injection framework such as Spring, create a bean for the <code>CloudFactory</code>.</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<p>Create a <code>CloudFactory</code> instance. Creation of a <code>CloudFactory</code> instance is a bit expensive, so we recommend using a singleton instance. If you are using a Dependency Injection framework such as Spring, create a bean for the <code>CloudFactory</code>.</p>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre class="CodeRay highlight"><code data-lang="java">CloudFactory cloudFactory = <span class="keyword">new</span> CloudFactory();</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ulist">
|
||||
<ul>
|
||||
</li>
|
||||
<li>
|
||||
<p>Obtain the <code>Cloud</code> object for the environment in which the application is running.</p>
|
||||
<div class="listingblock">
|
||||
@@ -569,79 +562,81 @@ table.CodeRay td.code>pre{padding:0}
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Note that you must have a <code>CloudConnector</code> suitable for your deployment environment on your classpath. For example, if you are deploying the application to Cloud Foundry, you must add the <a href="cloudfoundry-connector.html">Cloud Foundry Connector</a> to your classpath. If no suitable <code>CloudConnector</code> is found, the <code>getCloud()</code> method will throw a <code>CloudException</code>.</p>
|
||||
<p>Note that your classpath must have a <code>CloudConnector</code> suitable for your deployment environment---for example, if you are deploying the application to Cloud Foundry, you must add the <a href="cloudfoundry-connector.html">Cloud Foundry Connector</a> to your classpath. If the <code>getCloud()</code> method finds no suitable <code>CloudConnector</code>, it will throw a <code>CloudException</code>.</p>
|
||||
</div>
|
||||
</li>
|
||||
<li>
|
||||
<p>Use the <code>Cloud</code> instance to access application and service information and to create service connectors.</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre class="CodeRay highlight"><code data-lang="java"><span class="comment">// ServiceInfo has all the information necessary to connect to the underlying service</span>
|
||||
<pre class="CodeRay highlight"><code data-lang="java"><span class="comment">// ServiceInfo has all of the information necessary to connect to the underlying service</span>
|
||||
<span class="predefined-type">List</span><ServiceInfo> serviceInfos = cloud.getServiceInfos();</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre class="CodeRay highlight"><code data-lang="java"><span class="comment">// find the `ServiceInfo` definitions suitable for connecting to a particular service type</span>
|
||||
<pre class="CodeRay highlight"><code data-lang="java"><span class="comment">// Find the `ServiceInfo` definitions suitable for connecting to a particular service type</span>
|
||||
<span class="predefined-type">List</span><ServiceInfo> databaseInfos = cloud.getServiceInfos(<span class="predefined-type">DataSource</span>.class);</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre class="CodeRay highlight"><code data-lang="java"><span class="comment">// Alternately, let Spring Cloud create a service connector for you</span>
|
||||
<pre class="CodeRay highlight"><code data-lang="java"><span class="comment">// Alternatively, let Spring Cloud create a service connector for you</span>
|
||||
<span class="predefined-type">String</span> serviceId = <span class="string"><span class="delimiter">"</span><span class="content">inventory-db</span><span class="delimiter">"</span></span>;
|
||||
<span class="predefined-type">DataSource</span> ds = cloud.getServiceConnector(serviceId, <span class="predefined-type">DataSource</span>.class, <span class="predefined-constant">null</span> <span class="comment">/* default config */</span>);</code></pre>
|
||||
<span class="predefined-type">DataSource</span> ds = cloud.getServiceConnector(serviceId, <span class="predefined-type">DataSource</span>.class,
|
||||
<span class="predefined-constant">null</span> <span class="comment">/* default config */</span>);</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect1">
|
||||
<h2 id="_adding_cloud_connectors">Adding cloud connectors</h2>
|
||||
<h2 id="_adding_cloud_connectors">Adding Cloud Connectors</h2>
|
||||
<div class="sectionbody">
|
||||
<div class="paragraph">
|
||||
<p>A cloud provider may extend Spring Cloud by adding a new <code>CloudConnector</code> to make Spring Cloud work with a new cloud platform. The connector is responsible for telling whether the application is running in the specific cloud, identifying application information (such as the name and instance ID of the particular running instance), and mapping bound services (such as URIs exposed in environment variables) as <code>ServiceInfo</code> objects.</p>
|
||||
<p>A cloud provider may extend Spring Cloud by adding a new <code>CloudConnector</code> that tells Spring Cloud how to work with a new cloud platform. The connector is responsible for determining whether the application is running in the specific cloud, identifying application information (such as the name and instance ID of the particular running instance), and mapping bound services (such as URIs exposed in environment variables) as <code>ServiceInfo</code> objects.</p>
|
||||
</div>
|
||||
<div class="admonitionblock tip">
|
||||
<table>
|
||||
<tr>
|
||||
<td class="icon">
|
||||
<div class="title">Tip</div>
|
||||
</td>
|
||||
<td class="content">
|
||||
<div class="paragraph">
|
||||
<p>See the <a href="cloudfoundry-connector.html">Cloud Foundry Connector</a> and <a href="heroku-connector.html">Heroku Connector</a> for examples.</p>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Spring Cloud uses the Java SPI to discover available connectors. New cloud connectors should list the fully-qualified class name in the provider-configuration file at</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre>META-INF/services/org.springframework.cloud.CloudConnector</pre>
|
||||
</div>
|
||||
<p>Spring Cloud uses the Java SPI to discover available connectors. New cloud connectors should list the fully-qualified class name in the provider-configuration file at <code>META-INF/services/org.springframework.cloud.CloudConnector</code>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect1">
|
||||
<h2 id="_adding_service_discovery">Adding service discovery</h2>
|
||||
<h2 id="_adding_service_discovery">Adding Service Discovery</h2>
|
||||
<div class="sectionbody">
|
||||
<div class="paragraph">
|
||||
<p>To allow Spring Cloud to discover a new type of service (<code>HelloWorldService</code>), create a <code>ServiceInfo</code> class containing the information necessary to connect to your service. If your service can be specified via a URI, extend <code>UriBasedServiceInfo</code> and provide the URI scheme in a call to the <code>super</code> constructor.</p>
|
||||
<p>To allow Spring Cloud to discover a new type of service, create a <code>ServiceInfo</code> class containing the information necessary to connect to your service. If your service can be specified via a URI, extend <code>UriBasedServiceInfo</code> and provide the URI scheme in a call to the <code>super</code> constructor.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>This class will expose information for a service available at</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre>helloworld://username:password@host:port/Bonjour</pre>
|
||||
</div>
|
||||
<p>Consider an example <code>HelloWorldService</code>. The following class will expose information for a service available at <code>helloworld://username:password@host:port/Bonjour</code>.</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre class="CodeRay highlight"><code data-lang="java"><span class="directive">public</span> <span class="type">class</span> <span class="class">HelloWorldServiceInfo</span> <span class="directive">extends</span> UriBasedServiceInfo {
|
||||
<span class="directive">public</span> <span class="directive">static</span> <span class="directive">final</span> <span class="predefined-type">String</span> URI_SCHEME = <span class="string"><span class="delimiter">"</span><span class="content">helloworld</span><span class="delimiter">"</span></span>;
|
||||
|
||||
<span class="comment">// needed to support structured service definitions like Cloud Foundry</span>
|
||||
<span class="comment">// Needed to support structured service definitions such as Cloud Foundry's</span>
|
||||
<span class="directive">public</span> HelloWorldServiceInfo(<span class="predefined-type">String</span> id, <span class="predefined-type">String</span> host, <span class="type">int</span> port, <span class="predefined-type">String</span> username, <span class="predefined-type">String</span> password, <span class="predefined-type">String</span> greeting) {
|
||||
<span class="local-variable">super</span>(id, URI_SCHEME, host, port, username, password, greeting);
|
||||
}
|
||||
|
||||
<span class="comment">// needed to support URI-based service definitions like Heroku</span>
|
||||
<span class="comment">// Needed to support URI-based service definitions such as Heroku's</span>
|
||||
<span class="directive">public</span> HelloWorldServiceInfo(<span class="predefined-type">String</span> id, <span class="predefined-type">String</span> uri) {
|
||||
<span class="local-variable">super</span>(id, uri);
|
||||
}
|
||||
@@ -649,36 +644,31 @@ table.CodeRay td.code>pre{padding:0}
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Then you will need to create a <code>ServiceInfoCreator</code> for each cloud platform you want to support. You will probably want to extend the appropriate creator base class(es), such as <code>HerokuServiceInfoCreator</code>. This is often as simple as writing a method that instantiates a new <code>HelloWorldServiceInfo</code>.</p>
|
||||
<p>Next, create a <code>ServiceInfoCreator</code> for each cloud platform that you want to support. You will probably want to extend the appropriate creator base class(es), such as <code>HerokuServiceInfoCreator</code>. This is often as simple as (for example, in the case of the <code>HelloWorldService</code>) writing a method that instantiates a new <code>HelloWorldServiceInfo</code>.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Register your <code>ServiceInfoCreator</code> classes in the appropriate provider-configuration file for your cloud’s <code>ServiceInfoCreator</code> base class.</p>
|
||||
<p>Finally, register your <code>ServiceInfoCreator</code> classes in the appropriate provider-configuration file for your cloud’s <code>ServiceInfoCreator</code> base class.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect1">
|
||||
<h2 id="_adding_service_connectors">Adding service connectors</h2>
|
||||
<h2 id="_adding_service_connectors">Adding Service Connectors</h2>
|
||||
<div class="sectionbody">
|
||||
<div class="paragraph">
|
||||
<p>A service connector consumes a <code>ServiceInfo</code> discovered by the cloud connector and converts it into the appropriate service object, such as a <code>DataSource</code> for a service definition representing a SQL database.</p>
|
||||
<p>A service connector consumes a <code>ServiceInfo</code> discovered by the cloud connector and converts it into the appropriate service object (such as, in the case of a service definition representing a SQL database, a <code>DataSource</code>).</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Service connectors may be tightly bound to the framework whose service objects they are creating; for example, some connectors in the <a href="spring-cloud-spring-service-connector.html">Spring service connector</a> create connection factories defined by Spring Data, for use in building Spring Data templates.</p>
|
||||
<p>Service connectors may be tightly bound to the framework whose service objects they are creating. For example, in the <a href="spring-cloud-spring-service-connector.html">Spring Service Connector</a> library, some connectors create connection factories defined by Spring Data for use in building Spring Data templates.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>To add new service connectors, implement <code>ServiceConnectorCreator</code> in your connector classes and list the fully-qualified class names in the provider-configuration file at</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre>META-INF/services/org.springframework.cloud.service.ServiceConnectorCreator</pre>
|
||||
</div>
|
||||
<p>To add new service connectors, implement <code>ServiceConnectorCreator</code> in your connector classes and list the fully-qualified class names in the provider-configuration file at <code>META-INF/services/org.springframework.cloud.service.ServiceConnectorCreator</code>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="footer">
|
||||
<div id="footer-text">
|
||||
Last updated 2015-07-31 13:15:42 CDT
|
||||
Last updated 2015-07-31 14:26:44 CDT
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
@@ -506,7 +506,7 @@ table.CodeRay td.code>pre{padding:0}
|
||||
<div id="toc" class="toc">
|
||||
<div id="toctitle">Table of Contents</div>
|
||||
<ul class="sectlevel1">
|
||||
<li><a href="#_the_java_config">The Java Config</a>
|
||||
<li><a href="#_the_java_configuration">The Java Configuration</a>
|
||||
<ul class="sectlevel2">
|
||||
<li><a href="#_creating_service_beans">Creating Service Beans</a></li>
|
||||
<li><a href="#_connecting_to_generic_services">Connecting to Generic Services</a></li>
|
||||
@@ -530,23 +530,20 @@ table.CodeRay td.code>pre{padding:0}
|
||||
<div id="preamble">
|
||||
<div class="sectionbody">
|
||||
<div id="spring-cloud-connectors-install" class="paragraph">
|
||||
<p>Provides <code>ServiceConnectorCreator</code> implementation for <code>javax.sql.DataSource</code> and various spring-data connector factories.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Also provides Java config and the XML namespace support for connecting to cloud services as well as accessing cloud services and application properties.</p>
|
||||
<p>This library provides <code>ServiceConnectorCreator</code> implementations for <code>javax.sql.DataSource</code> and various <a href="http://projects.spring.io/spring-data/">Spring Data</a> connector factories. It also provides Java configuration and XML namespace support for connecting to cloud services, accessing cloud services, and accessing application properties.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect1">
|
||||
<h2 id="_the_java_config">The Java Config</h2>
|
||||
<h2 id="_the_java_configuration">The Java Configuration</h2>
|
||||
<div class="sectionbody">
|
||||
<div class="paragraph">
|
||||
<p>Typical use of Java config involves extending the <code>AbstractCloudConfig</code> class and adding methods with the <code>@Bean</code> annotation to create beans for services. Apps migrating from <a href="https://spring.io/blog/2011/11/04/using-cloud-foundry-services-with-spring-part-2-auto-reconfiguration/">auto-reconfiguration</a> might first try the <a href="#_scanning_for_services">service-scanning approach</a> until they need more explicit control. Java config also offers a way to expose application and service properties, should you choose to take a lower level access in creating service connectors yourself (or for debugging purposes, etc.).</p>
|
||||
<p>Typical use of the Java configuration involves extending the <code>AbstractCloudConfig</code> class and creating beans for services by annotating methods with the <code>@Bean</code> annotation. If you are migrating an application that uses <a href="https://spring.io/blog/2011/11/04/using-cloud-foundry-services-with-spring-part-2-auto-reconfiguration/">auto-reconfiguration</a>, you might first try the <a href="#_scanning_for_services">service-scanning approach</a> until you need more explicit control. The Spring Service Connector Java configuration also offers a way to expose application and service properties in case you want lower-level access when creating your own service connectors (or for debugging purposes, etc.).</p>
|
||||
</div>
|
||||
<div class="sect2">
|
||||
<h3 id="_creating_service_beans">Creating Service Beans</h3>
|
||||
<div class="paragraph">
|
||||
<p>In the following example, the configuration creates a <code>DataSource</code> bean connecting to the only relational database service bound to the app (it will fail if there is no such unique service). It also creates a <code>MongoDbFactory</code> bean, again, connecting to the only mongodb service bound to the app. Please check Javadoc for <code>AbstractCloudConfig</code> for ways to connect to other services.</p>
|
||||
<p>The configuration shown in the following example creates a <code>DataSource</code> bean that connects to the only relational database service bound to the application (it will fail if there is no such unique service). It also creates a <code>MongoDbFactory</code> bean, which again connects to the only MongoDB service bound to the application. (For ways to connect to other services, see the <a href="http://docs.spring.io/autorepo/docs/spring-cloud/current/api/org/springframework/cloud/config/java/AbstractCloudConfig.html">Javadoc for <code>AbstractCloudConfig</code></a>.)</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
@@ -566,10 +563,18 @@ table.CodeRay td.code>pre{padding:0}
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>The bean names will match the method names unless you specify an explicit value to the annotation such as <code>@Bean("inventory-service")</code> (this just follows how Spring’s Java configuration works).</p>
|
||||
<p>You can specify a bean name by providing a value in the <code>@Bean</code> annotation.</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre class="CodeRay highlight"><code data-lang="java"><span class="annotation">@Bean</span>(<span class="string"><span class="delimiter">"</span><span class="content">inventory-service</span><span class="delimiter">"</span></span>)</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>If you have more than one service of a type bound to the app or want to have an explicit control over the services to which a bean is bound, you can pass the service names to methods such as <code>dataSource()</code> and <code>mongoDbFactory()</code> as follows:</p>
|
||||
<p>Otherwise, bean names will match the method names. (This works in the same way as does Spring’s Java configuration.)</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>If you have more than one service of a type bound to the application or want explicit control over the services to which a bean is bound, you can pass the service names to methods such as <code>dataSource()</code> and <code>mongoDbFactory()</code>.</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
@@ -584,24 +589,24 @@ table.CodeRay td.code>pre{padding:0}
|
||||
<span class="keyword">return</span> connectionFactory().mongoDbFactory(<span class="string"><span class="delimiter">"</span><span class="content">document-service</span><span class="delimiter">"</span></span>);
|
||||
}
|
||||
|
||||
<span class="comment">//... more beans to obtain service connectors</span>
|
||||
<span class="comment">// (More beans to obtain service connectors)</span>
|
||||
}</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Method such as <code>dataSource()</code> come in a additional overloaded variant that offer specifying configuration options such as the pooling parameters. Please see Javadoc for more details.</p>
|
||||
<p>Methods such as <code>dataSource()</code> come in additional overloaded variants which let you specify configuration options (such as pooling parameters). See the relevant Javadocs for more information.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect2">
|
||||
<h3 id="_connecting_to_generic_services">Connecting to Generic Services</h3>
|
||||
<div class="paragraph">
|
||||
<p>Java config supports access to generic services (that don’t have a directly mapped method—​typical for a newly introduced service or connecting to a private service in private PaaS) through the <code>service()</code> method. It follows the same pattern as the <code>dataSource()</code> etc, except it allows supplying the connector type as an additional parameters.</p>
|
||||
<p>The Java configuration supports access to generic services (services which don’t have a directly mapped method; this is typical for a newly-introduced service or when connecting to a private service in a private PaaS) through the <code>service()</code> method. It follows the same pattern as <code>dataSource()</code> etc. except that it allows you to supply the connector type as an additional parameter.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect2">
|
||||
<h3 id="_scanning_for_services">Scanning for Services</h3>
|
||||
<div class="paragraph">
|
||||
<p>You can scan for each bound service using the <code>@ServiceScan</code> annotation as follows (conceptually similar to the @ComponentScan annotation in Spring):</p>
|
||||
<p>You can scan for each bound service using the <code>@ServiceScan</code> annotation. (This is conceptually similar to Spring’s <code>@ComponentScan</code> annotation.)</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
@@ -612,27 +617,30 @@ table.CodeRay td.code>pre{padding:0}
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Here, one bean of the appropriate type (<code>DataSource</code> for a relational database service, for example) will be created. Each created bean will have the <code>id</code> matching the corresponding service name. You can then inject such beans using auto-wiring:</p>
|
||||
<p>In the above example, the configuration will create one bean of the appropriate type (such as a <code>DataSource</code> in the case of a relational database service). Each bean will have an <code>id</code> matching the corresponding service name.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>You can inject such beans using autowiring.</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre>@Autowired DataSource inventoryDb;</pre>
|
||||
<pre class="CodeRay highlight"><code data-lang="java"><span class="annotation">@Autowired</span> <span class="predefined-type">DataSource</span> inventoryDb;</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>If the app is bound to more than one services of a type, you can use the <code>@Qualifier</code> annotation supplying it the name of the service as in the following code:</p>
|
||||
<p>If the application is bound to more than one service of a given type, you can use the <code>@Qualifier</code> annotation, providing it with the name of the appropriate service.</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre>@Autowired @Qualifier("inventory-db") DataSource inventoryDb;
|
||||
@Autowired @Qualifier("shipping-db") DataSource shippingDb;</pre>
|
||||
<pre class="CodeRay highlight"><code data-lang="java"><span class="annotation">@Autowired</span> <span class="annotation">@Qualifier</span>(<span class="string"><span class="delimiter">"</span><span class="content">inventory-db</span><span class="delimiter">"</span></span>) <span class="predefined-type">DataSource</span> inventoryDb;
|
||||
<span class="annotation">@Autowired</span> <span class="annotation">@Qualifier</span>(<span class="string"><span class="delimiter">"</span><span class="content">shipping-db</span><span class="delimiter">"</span></span>) <span class="predefined-type">DataSource</span> shippingDb;</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect2">
|
||||
<h3 id="_accessing_service_properties">Accessing Service Properties</h3>
|
||||
<div class="paragraph">
|
||||
<p>You can expose raw properties for all services and the app throught a bean as follows:</p>
|
||||
<p>You can expose raw properties for all services and for the application through a bean.</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
@@ -653,73 +661,75 @@ table.CodeRay td.code>pre{padding:0}
|
||||
<div class="sect2">
|
||||
<h3 id="_setting_up">Setting Up</h3>
|
||||
<div class="paragraph">
|
||||
<p>The <code><cloud></code> namespace offers a simple way for Spring application to connect to cloud services. To use this namespace, add a declaration for the cloud namespace:</p>
|
||||
<p>The <code><cloud></code> namespace offers a simple way for a Spring application to connect to cloud services.</p>
|
||||
</div>
|
||||
<div class="literalblock">
|
||||
<div class="paragraph">
|
||||
<p>To use this namespace, add a declaration for it.</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre><?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:cloud="http://www.springframework.org/schema/cloud"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/cloud http://www.springframework.org/schema/cloud/spring-cloud.xsd"></pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="literalblock">
|
||||
<div class="content">
|
||||
<pre><!-- <cloud> namespace usage here --></pre>
|
||||
<pre class="CodeRay highlight"><code data-lang="xml"><span class="preprocessor"><?xml version="1.0" encoding="UTF-8"?></span>
|
||||
<span class="tag"><beans</span> <span class="attribute-name">xmlns</span>=<span class="string"><span class="delimiter">"</span><span class="content">http://www.springframework.org/schema/beans</span><span class="delimiter">"</span></span>
|
||||
<span class="attribute-name">xmlns:xsi</span>=<span class="string"><span class="delimiter">"</span><span class="content">http://www.w3.org/2001/XMLSchema-instance</span><span class="delimiter">"</span></span>
|
||||
<span class="attribute-name">xmlns:cloud</span>=<span class="string"><span class="delimiter">"</span><span class="content">http://www.springframework.org/schema/cloud</span><span class="delimiter">"</span></span>
|
||||
<span class="attribute-name">xsi:schemaLocation</span>=<span class="string"><span class="delimiter">"</span><span class="content">http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd</span>
|
||||
<span class="content">http://www.springframework.org/schema/cloud http://www.springframework.org/schema/cloud/spring-cloud.xsd</span><span class="delimiter">"</span></span><span class="tag">></span>
|
||||
|
||||
<span class="comment"><!-- <cloud> namespace usage here --></span></code></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect2">
|
||||
<h3 id="_creating_service_beans_2">Creating Service Beans</h3>
|
||||
<div class="paragraph">
|
||||
<p>Each namespace element that creates a bean corresponding to a service follows the following pattern (example is for a relational service):</p>
|
||||
<p>A namespace element which creates a service bean conforms to the following pattern (in this example, the bean is being created for a relational database service).</p>
|
||||
</div>
|
||||
<div class="literalblock">
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre><cloud:data-source id="inventory-db" service-name="inventory-db-service">
|
||||
<cloud:connection properties="sessionVariables=sql_mode='ANSI';characterEncoding=UTF-8"/>
|
||||
<cloud:pool pool-size="20" max-wait-time="200"/>
|
||||
</cloud></pre>
|
||||
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag"><cloud:data-source</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">"</span><span class="content">inventory-db</span><span class="delimiter">"</span></span> <span class="attribute-name">service-name</span>=<span class="string"><span class="delimiter">"</span><span class="content">inventory-db-service</span><span class="delimiter">"</span></span><span class="tag">></span>
|
||||
<span class="tag"><cloud:connection</span> <span class="attribute-name">properties</span>=<span class="string"><span class="delimiter">"</span><span class="content">sessionVariables=sql_mode='ANSI';characterEncoding=UTF-8</span><span class="delimiter">"</span></span><span class="tag">/></span>
|
||||
<span class="tag"><cloud:pool</span> <span class="attribute-name">pool-size</span>=<span class="string"><span class="delimiter">"</span><span class="content">20</span><span class="delimiter">"</span></span> <span class="attribute-name">max-wait-time</span>=<span class="string"><span class="delimiter">"</span><span class="content">200</span><span class="delimiter">"</span></span><span class="tag">/></span>
|
||||
<span class="tag"></cloud></span></code></pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>This creates a <code>javax.sql.DataSource</code> bean with the <code>inventory-db</code> id, binding it to <code>inventory-db-service</code>. The created <code>DataSource</code> bean is configured with connection and pool properties as specified in the nested elements.
|
||||
When the <code>id</code> attribute is not specified, the service name is used as the <code>id</code>. When the <code>service-name</code> is not specified, the bean is bound to the only service in the corresponding category (relational database, in this case). If no unique service is found, a runtime exception is thrown.</p>
|
||||
<p>The above example creates a <code>javax.sql.DataSource</code> bean with the id <code>inventory-db</code>. The bean is bound to the <code>inventory-db-service</code> and is configured with the <code>connection</code> and <code>pool</code> properties specified in the nested <code><cloud:connection></code> and <code><cloud:pool></code> elements.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Other namespace elements that create service connector include:</p>
|
||||
<p>If no <code>id</code> attribute is specified, the <code>id</code> is set to the service name. If no <code>service-name</code> is specified, the bean is bound to the only service in the corresponding category (in this case, a relational database). If no unique service is found, a runtime exception will be thrown.</p>
|
||||
</div>
|
||||
<div class="literalblock">
|
||||
<div class="paragraph">
|
||||
<p>Other namespace elements which create service connectors include:</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre><cloud:mongo-db-factory/>
|
||||
<cloud:redis-connection-factory/>
|
||||
<cloud:rabbit-connection-factory/></pre>
|
||||
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag"><cloud:mongo-db-factory</span><span class="tag">/></span>
|
||||
<span class="tag"><cloud:redis-connection-factory</span><span class="tag">/></span>
|
||||
<span class="tag"><cloud:rabbit-connection-factory</span><span class="tag">/></span></code></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect2">
|
||||
<h3 id="_connecting_to_generic_services_2">Connecting to Generic Services</h3>
|
||||
<div class="paragraph">
|
||||
<p>We also supports a generic <code><cloud:service></code> namespace to allow connecting to a service that doesn’t have directly mapped element (typical for a newly introduced service or connecting to a private service in private PaaS). You must specify either the <code>connector-type</code> attribute (so that it can find a unique service matching that type) or the <code>service-name</code> attribute.</p>
|
||||
<p>Spring Service Connector also supports a generic <code><cloud:service></code> namespace for connecting to a service with no directly-mapped element (this is typical for a newly-introduced service or when connecting to a private service in a private PaaS). You must specify either the <code>connector-type</code> attribute (for locating a unique service by type) or the <code>service-name</code> attribute.</p>
|
||||
</div>
|
||||
<div class="literalblock">
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre><cloud:service id="email" service-name="email-service" connector-type="com.something.EmailConnectory/></pre>
|
||||
<pre class="CodeRay highlight"><code data-lang="xml"> <span class="tag"><cloud:service</span> <span class="attribute-name">id</span>=<span class="string"><span class="delimiter">"</span><span class="content">email</span><span class="delimiter">"</span></span> <span class="attribute-name">service-name</span>=<span class="string"><span class="delimiter">"</span><span class="content">email-service</span><span class="delimiter">"</span></span> <span class="attribute-name">connector-type</span>=<span class="string"><span class="delimiter">"</span><span class="content">com.something.EmailConnectory/</span></span><span class="error">></span></code></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect2">
|
||||
<h3 id="_scanning_for_services_2">Scanning for Services</h3>
|
||||
<div class="paragraph">
|
||||
<p>Besides these element that create one bean per element, we also support the <code><cloud:service-scan></code> element in the same spirit as the <code><context:component-scan></code> element. It scans for all the services bound to the app and creates a bean corresponding to each service. Each created bean has id that matches the service name to allow the use of the @Qualifier annotation along with @Autowired when more than one bean of the same type is introduced.</p>
|
||||
<p>Besides these elements (which create only one bean per element), Spring Service Connector provides a <code><cloud:service-scan></code> element, in the same spirit as the <code><context:component-scan></code> element. It scans for all services bound to the application and creates a bean for each service. Each bean has an <code>id</code> matching the service name; this means that you can use the <code>@Qualifier</code> annotation along with <code>@Autowired</code> when there is more than one bean of the same type.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect2">
|
||||
<h3 id="_accessing_service_properties_2">Accessing Service Properties</h3>
|
||||
<div class="paragraph">
|
||||
<p>Lastly, we support <code><cloud:properties></code> that exposes properties for the app and services.</p>
|
||||
<p>Lastly, Spring Service Connector provides a <code><cloud:properties></code> element, which exposes properties for the application and for services.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -727,7 +737,7 @@ When the <code>id</code> attribute is not specified, the service name is used as
|
||||
</div>
|
||||
<div id="footer">
|
||||
<div id="footer-text">
|
||||
Last updated 2015-07-31 13:16:06 CDT
|
||||
Last updated 2015-07-31 16:18:51 CDT
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user