Azure 部署似乎不适用于我在 Java EE 中使用 IntelliJ 和 Azure 工具的 Web 服务

Azure deployement seems not working with my web-service in Java EE with IntelliJ and Azure tools

我在 SCRUD 的 Java EE 中做了一个网络服务。我尝试将它放在 Azure web-app 上,因为我想将它用于另一个项目,如果我可以将它放在上面会更容易。但是当我在 Azure 上部署它时,我只能访问 index.jsp 页面。

我的类是这样的:

@Path("LikePost")
public class LikePostAPI extends RestApplication {
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("GetAll")
public Response getAll(){
    Connection conn= GetConnection.getInstance().getConnection();
    Response response= Response.status(Response.Status.OK).entity(new DaoLikePost(conn).getAll()).build();
    return response;
}
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("getLike")
public Response getLike(@QueryParam("id") int id) {
    Response response=null;
    Connection conn=GetConnection.getInstance().getConnection();
    Like l=new DaoLikePost(conn).find(id);
    if(l!=null)
        response=Response.status(Response.Status.OK).entity(l).build();
    else
        response=Response.status(Response.Status.NO_CONTENT).entity(null).build();
    return response;
}
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("CreateLike")
public Response createLike(@FormParam("dateLiked") String dateLike,@FormParam("user") String userId,@FormParam("post") String postId){
    Connection conn=GetConnection.getInstance().getConnection();
    Like l=new Like();
    l.setUser(new DaoUser(conn).find(Integer.parseInt(userId)));
    DateFormat dateFormat=new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
    Date date=null;
    try {
        date=dateFormat.parse(dateLike);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    l.setDateLiked(date);
    l.setPost(new DaoPost(conn).find(Integer.parseInt(postId)));
    Boolean test=new DaoLikePost(conn).create(l);
    Response response=null;
    if(test)
        response=Response.status(Response.Status.OK).entity(test).build();
    else
        response=Response.status(Response.Status.BAD_REQUEST).entity(test).build();
    return response;
}
@DELETE
@Path("DeleteLike")
@Produces(MediaType.APPLICATION_JSON)
public Response deleteLike(@QueryParam("id")int id){
    Connection conn=GetConnection.getInstance().getConnection();
    Like l=new DaoLikePost(conn).find(id);
    Boolean test=new DaoLikePost(conn).delete(l);
    Response response=null;
    if(test)
        response=Response.status(Response.Status.OK).entity(test).build();
    else
        response=Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(null).build();
    return response;
}
@PUT
@Path("UpdateLike")
@Produces(MediaType.APPLICATION_JSON)
public Response updateLike(@FormParam("id") String idLike,@FormParam("dateLiked") String dateLike,@FormParam("user") String userId,@FormParam("post") String postId){
    Connection conn=GetConnection.getInstance().getConnection();
    Like l=new Like();
    l.setId(Integer.parseInt(idLike));
    l.setUser(new DaoUser(conn).find(Integer.parseInt(userId)));
    Date date=null;
    DateFormat dateFormat=new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
    try {
        date=dateFormat.parse(dateLike);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    l.setDateLiked(date);
    l.setPost(new DaoPost(conn).find(Integer.parseInt(postId)));
    Boolean test=new DaoLikePost(conn).update(l);
    Response response=null;
    if(test)
        response=Response.status(Response.Status.OK).entity(test).build();
    else
        response=Response.status(Response.Status.BAD_REQUEST).entity(null).build();
    return response;
}
}

这是部署的配置:https://gyazo.com/fed4d79d5d3cb72a820073efd234feb2

爆炸的神器:https://gyazo.com/a948f72cff3b89fd86df7d820aa928eb

对于 war 文件:https://gyazo.com/7ac6ead33bd6a129a4ad2a7ec537acd0

Azure 网站是:https://faceapibook.azurewebsites.net/

首先,如果 Azure 不使用 IntelliJ,您必须确保您的应用程序 运行 通常在 Tomcat 或本地计算机上的 Jetty 中。

然后您可以按照下面的两个官方教程在您的 IntelliJ 中使用 Azure Toolkit 插件将其直接部署到 Azure。

  1. Create a Hello World web app for Azure using IntelliJ
  2. Publish a Spring Boot app as a Docker container by using the Azure Toolkit for IntelliJ

此外,如果您可以使导出的 war 文件在本地 tomcat 服务器上正常工作,您也可以按照 Deploy WAR file of the offical document Deploy your app to Azure App Service with a ZIP or WAR file to deploy the war file exported from your IntelliJ project, and see more details from the wiki page Deploying WAR files using wardeploy.

部分进行操作

甚至,当您在 Azure 门户 Application settings 选项卡中正确设置 Java 版本的值时,如下所示,您可以将 war 文件上传到 webapps直接在Kudo控制台路径wwwroot下的目录即可完成部署。