Closed
Description
Beans using org.springframework.transaction.support.SimpleTransactionScope fail to get instantiated because RabbitAdmin is not operating inside a transaction. I have a message producer that filters out duplicate messages per transaction. This is done with a transaction scoped Set bean. I know that my producer will only use this bean within that transaction. However, RabbitAdmin is getting every Collection bean, calling the size() method, which causes the class scoped proxy to try to instantiate the bean. This fails because it's not happening inside a transaction.
Sample code:
public static String TRANSACTION_SCOPE = "transaction";
@Bean(name = "sentBundles")
@Scope(value = TRANSACTION_SCOPE, proxyMode = ScopedProxyMode.TARGET_CLASS)
public Set<MessageBundle> sentBundles() {
return new HashSet<>();
}
@Bean
public static CustomScopeConfigurer customScope() {
CustomScopeConfigurer configurer = new CustomScopeConfigurer();
configurer.addScope(TRANSACTION_SCOPE, new SimpleTransactionScope());
return configurer;
}