Skip to content

Commit

Permalink
AMQP-598: Admin: Ignore Scoped and Prototype Beans
Browse files Browse the repository at this point in the history
JIRA: https://jira.spring.io/browse/AMQP-598

When looking for `Collection<Declarable>` using `getBeansOfType()` ignore
prototype/scoped beans and do not initialize FBs.
  • Loading branch information
garyrussell committed Apr 15, 2016
1 parent bfc854b commit 343aac8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -448,12 +448,16 @@ public void initialize() {
}

this.logger.debug("Initializing declarations");
Collection<Exchange> contextExchanges = new LinkedList<Exchange>(this.applicationContext.getBeansOfType(Exchange.class).values());
Collection<Queue> contextQueues = new LinkedList<Queue>(this.applicationContext.getBeansOfType(Queue.class).values());
Collection<Binding> contextBindings = new LinkedList<Binding>(this.applicationContext.getBeansOfType(Binding.class).values());
Collection<Exchange> contextExchanges = new LinkedList<Exchange>(
this.applicationContext.getBeansOfType(Exchange.class).values());
Collection<Queue> contextQueues = new LinkedList<Queue>(
this.applicationContext.getBeansOfType(Queue.class).values());
Collection<Binding> contextBindings = new LinkedList<Binding>(
this.applicationContext.getBeansOfType(Binding.class).values());

@SuppressWarnings("rawtypes")
Collection<Collection> collections = this.applicationContext.getBeansOfType(Collection.class).values();
Collection<Collection> collections = this.applicationContext.getBeansOfType(Collection.class, false, false)
.values();
for (Collection<?> collection : collections) {
if (collection.size() > 0 && collection.iterator().next() instanceof Declarable) {
for (Object declarable : collection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeoutException;

Expand All @@ -69,13 +70,15 @@
import org.springframework.amqp.rabbit.test.BrokerRunning;
import org.springframework.amqp.utils.test.TestUtils;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.context.support.GenericApplicationContext;

import com.rabbitmq.client.Channel;
Expand Down Expand Up @@ -243,6 +246,7 @@ public void testMultiEntities() {
admin.deleteExchange("e2");
admin.deleteExchange("e3");
admin.deleteExchange("e4");
assertNull(admin.getQueueProperties(ctx.getBean(Config.class).protypeQueueName));
ctx.close();
}

Expand Down Expand Up @@ -297,6 +301,8 @@ public void testIgnoreDeclarationExeptionsTimeout() throws Exception {
@Configuration
public static class Config {

public String protypeQueueName = UUID.randomUUID().toString();

@Bean
public ConnectionFactory cf() {
return new CachingConnectionFactory("localhost");
Expand Down Expand Up @@ -343,6 +349,14 @@ public List<Queue> qs() {
);
}

@Bean
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public List<Queue> prototypes() {
return Arrays.asList(
new Queue(this.protypeQueueName, false, false, true)
);
}

@Bean
public List<Binding> bs() {
return Arrays.asList(
Expand Down

0 comments on commit 343aac8

Please sign in to comment.