创建了带有终结点的简单的jersey rest api应用程序,但是一旦我们点击了终结点URL,它便适用于tomcat,但不适用于Apache KARAF

时间:2018-08-07 08:10:36

标签: apache-karaf karaf

下面为简单的运动衫休息应用程序创建的工件:

pom.xml

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.rest.jersey.demo</groupId>
    <artifactId>jerseydemo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <dependencies>
        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-server</artifactId>
            <version>2.20</version>
        </dependency>

        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet</artifactId>
            <version>2.20</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>4.0.0</version>
            <scope>provided</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
            <scope>provided</scope>
        </dependency>

    </dependencies>

    <build>
        <sourceDirectory>src</sourceDirectory>
        <finalName>jerseydemo</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <warSourceDirectory>WebContent</warSourceDirectory>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <instructions>
                        <Import-Package>
                            javax.ws.rs.*,
                            com.sun.jersey.api.core,
                            com.sun.jersey.spi.container.servlet
                        </Import-Package>
                        <Web-ContextPath>rest-bundle</Web-ContextPath>
                        <Webapp-Context>rest-bundle</Webapp-Context>
                        <_wab>WebContent</_wab>
                    </instructions>
                </configuration>
            </plugin>

        </plugins>
    </build>
</project>

现在创建的配置类文件:HelloWorldApplication.java

package com.jersey.demo.config;

import org.glassfish.jersey.server.ResourceConfig;

public class HelloWorldApplication extends ResourceConfig {
    public HelloWorldApplication() {
        packages("com.jersey.demo.services");
    }
}

现在创建了简单的Jersey rest API控制器:

package com.jersey.demo.services;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;

    @Path("/sayhello")
    public class HelloWorldService {
         @GET
            @Path("/{name}")
            public Response sayHello(@PathParam("name") String msg) {
                String output = "Hello, " + msg + "!";
                return Response.status(200).entity(output).build();
            }
    }

将war文件部署到Apache Karaf中之后,一旦我们点击以下URL,但在Tomcat中按预期方式工作,就会遇到以下错误。 在karaf中-我已经安装了Web容器功能。

URL:http://localhost:8181/jerseydemo/sayhello/AZHAR

遇到错误

HTTP错误404 访问/ jerseydemo / sayhello / AZHAR时出现问题。原因:

Not Found

由Jetty提供支持://9.4.6.v20170531

请建议我我需要做什么

关于, 阿扎尔

0 个答案:

没有答案