简体   繁体   English

在Azure API App Services上部署JAX-RS Java API Webapp

[英]Deploying a JAX-RS Java API Webapp on Azure API App Services

So I'm trying to deploy a Java RESTful API app built using JAX-RS and Jersey. 因此,我正在尝试部署使用JAX-RS和Jersey构建的Java RESTful API应用。 Specifically this example[1]. 具体来说就是这个例子[1]。 It is able to run locally on a Tomcat 8.5 server without any problems and it can be deployed as a Docker Container using the Eclipse Azure toolkit. 它能够在Tomcat 8.5服务器上本地运行而不会出现任何问题,并且可以使用Eclipse Azure工具箱将其部署为Docker容器。

My issue arises when I try to follow this[2] guide to deploy the app using Azure's API App services. 当我尝试按照本指南[2]使用Azure的API应用程序服务部署应用程序时,就会出现我的问题。 The paths that are working locally eg "localhost:8080/RESTfulExample/rest/hello/mkyong" do not respond when deployed on Azure. 在本地工作的路径(例如“ localhost:8080 / RESTfulExample / rest / hello / mkyong”)在Azure上部署时不会响应。 eg when trying "apidemo.azurewebsites.net/RESTfulExample/rest/hello/mkyong" I get a 404 HTTP response where the description is "The requested resource is not available." 例如,当尝试“ apidemo.azurewebsites.net/RESTfulExample/rest/hello/mkyong”时,我得到一个404 HTTP响应,其描述为“请求的资源不可用”。

This is the web.xml 这是web.xml

<web-app id="WebApp_ID" version="2.4"
 xmlns="http://java.sun.com/xml/ns/j2ee" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
 <display-name>Restful Web Application</display-name>
 <servlet>
    <servlet-name>jersey-serlvet</servlet-name>
    <servlet-
 class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>com.mkyong.rest</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
 </servlet>
 <servlet-mapping>
    <servlet-name>jersey-serlvet</servlet-name>
    <url-pattern>/rest/*</url-pattern>
 </servlet-mapping>
</web-app>

This is the main java file 这是主要的Java文件

package com.mkyong.rest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
@Path("/hello")
public class HelloWorldService {
    @GET
    @Path("/{param}")
    public Response getMsg(@PathParam("param") String msg) {
        String output = "Jersey say : " + msg;
        return Response.status(200).entity(output).build();
    }
}
  1. https://www.mkyong.com/webservices/jax-rs/jersey-hello-world-example/ https://www.mkyong.com/webservices/jax-rs/jersey-hello-world-example/
  2. https://docs.microsoft.com/en-us/azure/app-service-api/app-service-api-java-api-app https://docs.microsoft.com/en-us/azure/app-service-api/app-service-api-java-api-app

try this: 尝试这个:

    <servlet>
    <servlet-name>jersey-serlvet</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>com.mkyong.rest</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

And ensure you using jersey 2 and all jars needed are loaded in WEB-INF/lib on your war, also check for the name of the war, and if you working on eclipse check this: org.eclipse.wst.common.component property: context-root 并确保您使用jersey 2,并且在战争中将所有需要的jar加载到WEB-INF / lib中,还检查战争的名称,如果正在使用eclipse,请检查以下内容:org.eclipse.wst.common.component属性:上下文根

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM