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

hfsqlsce  于 5个月前  发布在  Spring
关注(0)|答案(1)|浏览(34)
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>


我的application.properties:
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");
    }
}


应用程序正确启动。我看到消息:Started route 1(rest://get:/hello)
但是当我调用http://localhost:9090/hello时,我总是得到状态404
这个问题已经困扰我几天了。任何帮助都将不胜感激。

pokxtpni

pokxtpni1#

尝试使用
http://localhost:9090/camel/hello
而不是
http://localhost:9090/hello
我遇到了类似的问题,在路径中添加“ Camel ”对我来说很有效。

相关问题