Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
RhugwedaShedge opened this issue Jun 13, 2024 · 4 comments

Comments

@RhugwedaShedge
Copy link

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
Copy link
Contributor

olegz commented Jun 13, 2024

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
Copy link
Author

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
Copy link
Contributor

olegz commented Jun 14, 2024

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

@olegz
Copy link
Contributor

olegz commented Jul 2, 2024

Closing due to lack of follow up from the reporter

@olegz olegz closed this as completed Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants