Spring-amqp RabbitMQ - no exchange 'myexchange' in vhost '/' ERROR
<p>I know this question has been asked before but I couldnot find any suitable solution to my problem, hence posting it again. </p>

<p>I am trying to write a rabbitmq producer using spring-amqp to publish my messages on direct queue. Since its a producer application, my exchange and queue have to be created. Also I am not defining any listener bean as I do not need it at the producer end.
Below is my <strong><em>rabbitmq-config.xml</em></strong>:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xsi:schemaLocation="http://www.springframework.org/schema/rabbit
http://www.springframework.org/schema/rabbit/spring-rabbit-1.5.xsd
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd"&gt;

&lt;!-- Spring AMQP Admin --&gt;
&lt;rabbit:admin id="amqpAdmin"
    connection-factory="rabbitmqConnectionFactory"
    auto-startup="true" /&gt;

&lt;!-- Spring AMQP Template --&gt;
&lt;rabbit:template id="amqpTemplate"
    connection-factory="rabbitmqConnectionFactory"
    routing-key="my.key" exchange="my.exchange" 
    channel-transacted="true"/&gt;

&lt;!-- Connection Factory --&gt;
&lt;rabbit:connection-factory id="rabbitmqConnectionFactory"
    host="${rabbitmq.host:localhost}" 
    port="${rabbitmq.port:5672}" 
    username="${rabbitmq.username}"
    password="${rabbitmq.password}" 
    virtual-host="${rabbitmq.vhost:/}"
    cache-mode="CONNECTION" 
    channel-cache-size="${rabbitmq.channel-cache-size:25}" /&gt;

&lt;!-- Queue and Exchange --&gt;
&lt;rabbit:queue id="my.queue" durable="false"
    auto-declare="true" auto-delete="true" /&gt;

&lt;rabbit:direct-exchange name="my.exchange" durable="false"
    auto-declare="true" auto-delete="true" declared-by="amqpAdmin"&gt;
    &lt;rabbit:bindings&gt;
        &lt;rabbit:binding queue="my.queue" key="my.key"/&gt;
    &lt;/rabbit:bindings&gt;
&lt;/rabbit:direct-exchange&gt;
&lt;/beans&gt;
</code></pre>

<p>I just have a simple producer class, which uses the above <em>amqpTemplate</em> to send a message. 
But when I try running my producer application, all I get is:
 <strong>no exchange 'my.exchange' in vhost '/' ERROR</strong></p>

<blockquote>
<pre><code>ERROR CachingConnectionFactory:1089 - Channel shutdown: channel error; protocol method: #method&lt;channel.close&gt;(reply-code=404, reply-text=NOT_FOUND - no exchange 'my.exchange' in vhost '/', class-id=60, method-id=40)
DEBUG CachingConnectionFactory:842 - Detected closed channel on exception.  Re-initializing: AMQChannel(amqp://s3conn@127.0.0.1:5672/,1)
DEBUG RabbitResourceHolder:189 - Rolling back messages to channel: Cached Rabbit Channel: AMQChannel(amqp://s3conn@127.0.0.1:5672/,1), conn: Proxy@17a7f733 Dedicated Rabbit Connection: SimpleConnection@2118cddf [delegate=amqp://s3conn@127.0.0.1:5672/]
TRACE CachingConnectionFactory:906 - Returning cached Channel: AMQChannel(amqp://s3conn@127.0.0.1:5672/,1)
Exception in thread "main"
DEBUG CachingConnectionFactory:1008 - Returning connection 'Proxy@17a7f733 Dedicated Rabbit Connection: SimpleConnection@2118cddf [delegate=amqp://s3conn@127.0.0.1:5672/]' to cache
org.springframework.amqp.AmqpIOException: java.io.IOException
    at org.springframework.amqp.rabbit.connection.RabbitUtils.commitIfNecessary(RabbitUtils.java:105)
    at org.springframework.amqp.rabbit.core.RabbitTemplate.doSend(RabbitTemplate.java:1354)
    at org.springframework.amqp.rabbit.core.RabbitTemplate$3.doInRabbit(RabbitTemplate.java:623)
    at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1298)
    at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1271)
    at org.springframework.amqp.rabbit.core.RabbitTemplate.send(RabbitTemplate.java:619)
    at org.springframework.amqp.rabbit.core.RabbitTemplate.send(RabbitTemplate.java:613)
    at org.springframework.amqp.rabbit.core.RabbitTemplate.send(RabbitTemplate.java:603)
    at com.symantec.spe.cloud.amqpclient.JsonMessagePublisherImpl.sendMessage(JsonMessagePublisherImpl.java:53)
    at com.symantec.spe.cloud.amqpclient.test.TestProducer.main(TestProducer.java:50)
Caused by: java.io.IOException
    at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:106)
    at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:102)
    at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:124)
    at com.rabbitmq.client.impl.ChannelN.txCommit(ChannelN.java:1163)
    at com.rabbitmq.client.impl.ChannelN.txCommit(ChannelN.java:61)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.amqp.rabbit.connection.CachingConnectionFactory$CachedChannelInvocationHandler.invoke(CachingConnectionFactory.java:835)
    at com.sun.proxy.$Proxy7.txCommit(Unknown Source)
    at org.springframework.amqp.rabbit.connection.RabbitUtils.commitIfNecessary(RabbitUtils.java:103)
    ... 9 more
Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method&lt;channel.close&gt;(reply-code=404, reply-text=NOT_FOUND - no exchang
e 'my.exchange' in vhost '/', class-id=60, method-id=40)
    at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:67)
    at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:33)
    at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:361)
    at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:226)
    at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:118)
    ... 18 more
Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method&lt;channel.close&gt;(reply-code=404, reply-text=NOT_FOUND - no exchang
e 'my.exchange' in vhost '/', class-id=60, method-id=40)
    at com.rabbitmq.client.impl.ChannelN.asyncShutdown(ChannelN.java:484)
    at com.rabbitmq.client.impl.ChannelN.processAsync(ChannelN.java:321)
    at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:144)
    at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:91)
    at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:554)
    at java.lang.Thread.run(Unknown Source)
</code></pre>
</blockquote>

<p>Any help on this would be really appreciated. Thanks.</p>