使用 Apache Camel Servlet 组件获取状态为 404 的白标签页面

问题描述 投票:0回答:1
I am using Camel to provide a web service to other systems. I wrote a simple Camel consuming route to accept the http requests. I can successfully start the Camel application using Springboot. But When I access it through web browser. I always got HTTP 404 error

我使用的是Camel 4.2.0。这是我的 POM:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.4</version>
    </parent>
    <groupId>com.camel.rest</groupId>
    <artifactId>testapp</artifactId>
    <version>1.0-SNAPSHOT</version>


    <properties>
        <camel.version>4.2.0</camel.version>
        <java.version>17</java.version>
    </properties>


    <dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>3.1.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel.springboot</groupId>
            <artifactId>camel-spring-boot-starter</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jackson</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel.springboot</groupId>
            <artifactId>camel-servlet-starter</artifactId>
            <version>3.21.1</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

我的应用程序.属性:

camel.component.servlet.mapping.context-path=/*

服务器端口=9090

我有一个非常简单的路线:

@Component
public class respRoute extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        restConfiguration().component("servlet").port(9090).host("localhost").bindingMode(RestBindingMode.json);

        rest().get("/hello").produces(MediaType.APPLICATION_JSON_VALUE).to("direct:hello");
        from("direct:hello").transform().constant("Welcome buddy");
    }
}

应用程序正常启动。我看到消息: 开始路线1 (rest://get:/hello)

但是当我调用 http://localhost:9090/hello 时,我总是得到状态 404

这个问题困扰了我几天。任何帮助将不胜感激。

spring-boot apache-camel spring-camel camel-rest
1个回答
0
投票

尝试使用

http://localhost:9090/camel/hello

而不是

http://localhost:9090/你好

我遇到了类似的问题,在路径中添加“camel”对我有用。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.