设置rabbitTemplate和controller的scope都为prototype即可
@Bean
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public RabbitTemplate noSingleRabbitTemplate() throws IOException, TimeoutException {
RabbitTemplate rabbitTemplate = new RabbitTemplate(connection());
rabbitTemplate.setMandatory(true);
rabbitTemplate.setReceiveTimeout(30000);
rabbitTemplate.setReplyTimeout(30000);
return rabbitTemplate;
}
加粗样式
@RestController
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@RequestMapping("/sendMessage/")
public class SendMessageController {
@Resource(name = "noSingleRabbitTemplate")
private RabbitTemplate noSingleRabbitTemplate;
}
|