过去几天我一直在研究 Camel 和 REST DSL 的基本演示,但我终于遇到了这个问题。我对 Spring Boot 的魔法还很陌生,所以非常感谢任何反馈!
当我运行该项目时,对于我的两条路线,一切看起来都正确启动。但是,当我尝试 GET 请求时,总是会收到 404“未找到”消息。
我仅有的两个类在同一个包中,所以我认为可见性不是问题。我将项目创建为 Spring Start 项目,并将其作为 Spring Boot 应用程序运行。日志显示两条路由启动成功,Tomcat使用的是8080端口。上下文路径具体在application.properties文件中配置。
我的主要应用类:
包 com.example.demo;
import org.apache.camel.CamelContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@SpringBootApplication
@Configuration
@ComponentScan("com.example.demo")
public class DemoApplication {
@Autowired
CamelContext camelContext;
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
我的路由器类:
package com.example.demo;
import org.springframework.stereotype.Component;
import org.apache.camel.LoggingLevel;
import org.apache.camel.model.rest.RestBindingMode;
import org.apache.camel.builder.RouteBuilder;
@Component
public class DemoCamelRouter extends RouteBuilder {
@Override
public void configure() throws Exception { …Run Code Online (Sandbox Code Playgroud)