spring-cloud / spring-cloud-stream

Framework for building Event-Driven Microservices
http://cloud.spring.io/spring-cloud-stream
Apache License 2.0
993 stars 606 forks source link

Bean of type 'org.springframework.cloud.stream.function.StreamBridge' could not be found #2960

Closed RhugwedaShedge closed 3 months ago

RhugwedaShedge commented 3 months ago

I am using Spring Cloud Stream and RabbitMQ to send message to a channel. I have Autowired StreamBridge -

@Autowired private StreamBridge streamBridge;

@Override
  public void sendMessage(List<String> messages) {
    for (String message : messages) {
      streamBridge.send(
          "output",
          MessageBuilder.withPayload(message)
              .setHeader(MessageHeaders.CONTENT_TYPE, "application/json")
              .build());
      log.info("Message sent successfully: {}", message);
    }
  }

Still I am getting the error required a bean of type 'org.springframework.cloud.stream.function.StreamBridge' that could not be found. Action:Consider defining a bean of type 'org.springframework.cloud.stream.function.StreamBridge' in your configuration.

Spring-boot version - 3.2.1 spring-cloud-stream - 4.1.1

Spring-cloud-stream

RabbitMQ

olegz commented 3 months ago

It doesn't appear your application is being properly autowired due to some missconfiguration on your end. Can you please share your application in a zip or push to github so we can take a look

RhugwedaShedge commented 3 months ago

Thank you for responding but unfortunately I can't share the entire code

@EnableResourceServerSecurity
@SpringBootApplication
@EnableScheduling
@EnableFeignClients
@EnableCaching
@EnableResourceAccessManagement
@EnableAutoConfiguration(exclude = {ErrorMvcAutoConfiguration.class})
public class Application {
  public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
  }
}

These are the dependencies

dependencies {
  implementation org.springframework.cloud.spring.cloud.stream.binder.rabbit
  implementation org.springframework.amqp.spring.rabbit

    implementation org.springframework.security.oauth.spring.security.oauth2
    implementation org.springframework.cloud.spring.cloud.stream
    implementation org.springframework.amqp.spring.amqp
    implementation org.springframework.cloud.spring.cloud.function.context
    implementation org.springframework.integration.spring.integration.amqp
    implementation org.springframework.integration.spring.integration.core

    implementation group: 'org.springframework', name: 'spring-beans', version: '6.1.6'
    implementation group: 'org.springframework', name: 'spring-core', version: '6.1.6'
}

The properties file

spring.rabbitmq.host=${URL}
spring.rabbitmq.port=${PORT}
spring.rabbitmq.username=${USERNAME}
spring.rabbitmq.password=${PASSWORD}

spring.mvc.pathmatch.matching-strategy=ANT_PATH_MATCHER
spring.cloud.stream.bindings.output.destination=${..}
spring.cloud.stream.bindings.output.content-type=application/json
spring.cloud.stream.bindings.output.binder=rabbit

spring.cloud.stream.bindings.input-in-0.destination=${...}
spring.cloud.stream.bindings.input-in-0.content-type=application/json
spring.cloud.stream.bindings.input-in-0.binder=rabbit
spring.cloud.stream.bindings.input-in-0.group=${...}
spring.cloud.stream.bindings.input-in-0.consumer.queueNameGroupOnly=true
olegz commented 3 months ago

What about the class that autowires StreamBridge? Can you post that?

olegz commented 3 months ago

Closing due to lack of follow up from the reporter