0

I have a very simple camel route that I want to run:

@Component
public class MyRoute extends RouteBuilder {

  @Override
  public void configure() throws Exception {
    from("direct:start")
    .log(LoggingLevel.INFO, "Hello World");
  }

}

To do this I wrote a test

@SpringBootTest
@CamelSpringBootTest
@DisableJmx
@BootstrapWith(SpringBootTestContextBootstrapper.class)
public class MyRouteTest {

  @Autowired
  private ProducerTemplate producerTemplate;

  @Test
  void testRoute(){
    producerTemplate.requestBody("direct:start", "test");

  }

}

I get error:

Unsatisfied dependency expressed through field 'producerTemplate'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.apache.camel.ProducerTemplate' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

I found something similar from here: Spring Boot Camel Testing

I tried @BootstrapWith and also @EnableAutoConfiguration but they don't seem to help either.

u4963840
  • 81
  • 1
  • 8
  • if you are using latest camel and spring boot, hopefully this will help you to navigate this issue: https://camel.apache.org/components/3.20.x/others/test-spring-junit5.html – dkb Mar 15 '23 at 18:37
  • That is I should add `properties = { "camel.springboot.name=customName" }` to `@SpringBootTest`? That Didn't help. Also `@CamelSpringTest` didn't help. – u4963840 Mar 16 '23 at 09:53
  • 1
    Generate new project using [camel-spring-boot-archetype](https://camel.apache.org/manual/camel-maven-archetypes.html) and it shows you how to setup camel and camel unit tests. Camel 3.20.2 example unit test class only has annotations `@SpringBootTest` and `@CamelSpringBootTest` and the test works fine at least on my machine. – Pasi Österman Mar 17 '23 at 10:15
  • Tnx. Whyle I never learned what was wrong in my original post, at least this archetype helped me to get some project where I can lean and practice camel. – u4963840 Mar 20 '23 at 09:40

0 Answers0