最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - Making minimal example of an Apache Camel Jetty-based server work - Stack Overflow

programmeradmin0浏览0评论

I want to build a REST interface to a database using Apache Camel's Jetty component. However, I am struggling with the first steps, so I want to make a minimal example work.

I have a component class:

@Component
public class myRouteBuilder extends RouteBuilder {
    from("jetty::8080/").log("Request received.").setBody(simple("Huhu y'all!"));
}

Which is kicked off by a SpringBoot starter class:

@SpringBootApplication
public class RestServiceApplication {

    private static CountDownLatch _stopLatch = null;

    public static void main(String[] args) {

        SpringApplication theApp = new SpringApplication(myRouteBuilder.class);
     
        // variant 1 causing to happen nothing
        theApp.setWebApplicationType(WebApplicationType.NONE);
        // variant 2 causing an execption
        theApp.setWebApplicationType(WebApplicationType.SERVLET);

        try {
            ConfigurableApplicationContext appContext = theApp.run();
            appContext.registerShutdownHook();
        } catch (Exception e) {
            ...
            return;
        }

        _stopLatch = new CountDownLatch(1);
        try {
            _stopLatch.await();
        } catch (InterruptedException e) {
            ...
        }
    }
}

Variant 1 causes a curl http://localhost:8080/ to come back with "Failed to connect to localhost port 8080: Connection refused"

Variant 2 causes exception

Unable to start web server; nested exception is org.springframework.boot.web.context.MissingWebServerFactoryBeanException: No qualifying bean of type 'org.springframework.boot.web.servlet.server.ServletWebServerFactory' available: Unable to start AnnotationConfigServletWebServerApplicationContext due to missing ServletWebServerFactory bean

POM dependencies:

  <dependencies>
    <!-- for REST deployment in Tomcat server --> 
    <dependency>
      <groupId>org.apache.camel.springboot</groupId>
      <artifactId>camel-servlet-starter</artifactId>
    </dependency>
    
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-jetty</artifactId>
    </dependency>
    
    <dependency>
      <groupId>org.apache.camel.springboot</groupId>
      <artifactId>camel-jetty-starter</artifactId>
    </dependency>
    
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
  </dependencies>

I must admit that I didn't understand how SpringBoot and all this works, so I copy pasted so far, but now I need some guidance. How can

发布评论

评论列表(0)

  1. 暂无评论