camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Claus Ibsen (Confluence)" <conflue...@apache.org>
Subject [CONF] Apache Camel > Bean Injection
Date Thu, 14 Nov 2013 16:59:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/en/2176/1/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CAMEL/Bean+Injection">Bean
Injection</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
        <br/>
                         <h4>Changes (2)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-unchanged" >h3. Bean Injection <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >We support the injection of various
resources using <span class="diff-changed-words">@EndpointInject<span class="diff-added-chars"style="background-color:
#dfd;"> or @BeanInject</span>.</span> This can be used to inject <br></td></tr>
            <tr><td class="diff-unchanged" > <br>* [Endpoint] instances
which can be used for testing when used with [Mock] endpoints; see the [Spring Testing] for
an example. <br>* [ProducerTemplate] instances for [POJO Producing] <br>* client
side proxies for [POJO Producing] which is a simple approach to [Spring Remoting] <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">
<br>h4. Using @BeanInject <br> <br>From *Camel 2.13* onwards you can inject
beans (obtained from the [Registry]) into your beans such as {{RouteBuilder}} classes.  <br>
<br>For example to inject a bean named foo, you can enlist the bean in the [Registry]
such as in a Spring XML file: <br> <br>{code:xml} <br>&lt;bean id=&quot;foo&quot;
class=&quot;com.foo.MyFooBean&quot;/&gt; <br>{code} <br> <br>And
then in a Java {{RouteBuilder}} class, you can inject the bean using {{@BeanInject}} as shown
below: <br>{code} <br>public class MyRouteBuilder extends RouteBuilder { <br>
<br>   @BeanInject(&quot;foo&quot;) <br>   MyFooBean foo; <br> <br>
  public void configure() throws Exception { <br>     .. <br>   } <br>}
<br>{code} <br> <br>If you omit the name, then Camel does a lookup by type,
and injects the bean if there is exactly only one bean of that type enlisted in the [Registry].
<br>{code} <br>   @BeanInject <br>   MyFooBean foo; <br>{code} <br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h3><a name="BeanInjection-BeanInjection"></a>Bean Injection</h3>

<p>We support the injection of various resources using @EndpointInject or @BeanInject.
This can be used to inject</p>

<ul>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a>
instances which can be used for testing when used with <a href="/confluence/display/CAMEL/Mock"
title="Mock">Mock</a> endpoints; see the <a href="/confluence/display/CAMEL/Spring+Testing"
title="Spring Testing">Spring Testing</a> for an example.</li>
	<li><a href="/confluence/display/CAMEL/ProducerTemplate" title="ProducerTemplate">ProducerTemplate</a>
instances for <a href="/confluence/display/CAMEL/POJO+Producing" title="POJO Producing">POJO
Producing</a></li>
	<li>client side proxies for <a href="/confluence/display/CAMEL/POJO+Producing" title="POJO
Producing">POJO Producing</a> which is a simple approach to <a href="/confluence/display/CAMEL/Spring+Remoting"
title="Spring Remoting">Spring Remoting</a></li>
</ul>


<h4><a name="BeanInjection-Using@BeanInject"></a>Using @BeanInject</h4>

<p>From <b>Camel 2.13</b> onwards you can inject beans (obtained from the
<a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>) into
your beans such as <tt>RouteBuilder</tt> classes. </p>

<p>For example to inject a bean named foo, you can enlist the bean in the <a href="/confluence/display/CAMEL/Registry"
title="Registry">Registry</a> such as in a Spring XML file:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
&lt;bean id="foo" class="com.foo.MyFooBean"/&gt;
</pre>
</div></div>

<p>And then in a Java <tt>RouteBuilder</tt> class, you can inject the bean
using <tt>@BeanInject</tt> as shown below:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
public class MyRouteBuilder extends RouteBuilder {

   @BeanInject("foo")
   MyFooBean foo;

   public void configure() throws Exception {
     ..
   }
}
</pre>
</div></div>

<p>If you omit the name, then Camel does a lookup by type, and injects the bean if there
is exactly only one bean of that type enlisted in the <a href="/confluence/display/CAMEL/Registry"
title="Registry">Registry</a>.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
   @BeanInject
   MyFooBean foo;
</pre>
</div></div>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;" class="grey">
                        <a href="https://cwiki.apache.org/confluence/users/removespacenotification.action?spaceKey=CAMEL">Stop
watching space</a>
            <span style="padding: 0px 5px;">|</span>
                <a href="https://cwiki.apache.org/confluence/users/editmyemailsettings.action">Change
email notification preferences</a>
</div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Bean+Injection">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=98508&revisedVersion=2&originalVersion=1">View
Changes</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message