使用JBoss部署REST服务时出现问题

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用JBoss部署REST服务时出现问题相关的知识,希望对你有一定的参考价值。

我必须创建一个REST服务并将其部署在JBoss服务器上。现在它只是用“hello”字符串响应任何POST请求(我只需要测试至少是否有效)。

对于技术限制,我不得不使用jdk 1.7。它使用Java编写,使用Maven,并使用Spring MVC。

代码,就像我一无所知,应该有效。战争它是成功部署的,根据jboss'日志,我想它正在按照我的预期绘制资源。问题是,当我发送POST请求到我期望的URI(X.X.X.X:8080 / sduca / OSSreceiver)时,找不到资源。

我真的找不到原因或方法。我的前提是我从未做过这样的事情,但据同事说它应该有效。可能是什么原因?我错过了什么?

对不起如果我把整个项目(我讨厌是谁),但我认为这是必要的,因为我输入的每一行都可能是愚蠢的。

不管怎么说,还是要谢谢你! :)

我得到的回应

JBWEB000065: HTTP Status 404 - /sduca/OSSreceiver

JBWEB000309: type JBWEB000067: Status report

JBWEB000068: message /sduca/OSSreceiver

JBWEB000069: description JBWEB000124: The requested resource is not available.

这里有我部署时写的日志:

[0m[0m15:12:53,106 INFO  [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 2) JBAS015009: Scan found incompletely copied file content for deployment /opt/UTM/jboss/standalone/deployments/sduca-consumer-listener-1.0-SNAPSHOT.war. Deployment changes will not be processed until all content is complete.
[0m[0m15:13:02,076 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-7) JBAS015876: Starting deployment of "sduca-consumer-listener-1.0-SNAPSHOT.war" (runtime-name: "sduca-consumer-listener-1.0-SNAPSHOT.war")
[0m[33m15:13:02,888 WARN  [org.jboss.as.ee] (MSC service thread 1-11) JBAS011006: Not installing optional component org.springframework.http.server.ServletServerHttpAsyncRequestControl due to an exception (enable DEBUG log level to see the cause)
[0m[33m15:13:02,889 WARN  [org.jboss.as.ee] (MSC service thread 1-11) JBAS011006: Not installing optional component org.springframework.web.context.request.async.StandardServletAsyncWebRequest due to an exception (enable DEBUG log level to see the cause)
[0m[0m15:13:02,926 INFO  [org.jboss.web] (ServerService Thread Pool -- 219) JBAS018210: Register web context: /sduca
[0m[0m15:13:02,945 INFO  [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/sduca]] (ServerService Thread Pool -- 219) 1 Spring WebApplicationInitializers detected on classpath
[0m[0m15:13:03,005 INFO  [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/sduca]] (ServerService Thread Pool -- 219) Initializing Spring root WebApplicationContext
[0m[0m15:13:03,006 INFO  [org.springframework.web.context.ContextLoader] (ServerService Thread Pool -- 219) Root WebApplicationContext: initialization started
[0m[0m15:13:03,024 INFO  [org.springframework.web.context.support.AnnotationConfigWebApplicationContext] (ServerService Thread Pool -- 219) Refreshing Root WebApplicationContext: startup date [Thu Aug 30 15:13:03 CEST 2018]; root of context hierarchy
[0m[0m15:13:03,100 INFO  [org.springframework.web.context.support.AnnotationConfigWebApplicationContext] (ServerService Thread Pool -- 219) Registering annotated classes: [class com.hpe.oss.eventhandler.sduca.receiver.config.AppConfig]
[0m[0m15:13:03,483 INFO  [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] (ServerService Thread Pool -- 219) JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
[0m[0m15:13:03,809 INFO  [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (ServerService Thread Pool -- 219) Mapped "{[/OSSreceiver],methods=[POST]}" onto public java.lang.String com.hpe.oss.eventhandler.sduca.receiver.OSSreceiver.postResponse()
[0m[0m15:13:04,071 INFO  [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter] (ServerService Thread Pool -- 219) Looking for @ControllerAdvice: Root WebApplicationContext: startup date [Thu Aug 30 15:13:03 CEST 2018]; root of context hierarchy
[0m[0m15:13:04,188 INFO  [org.springframework.web.context.ContextLoader] (ServerService Thread Pool -- 219) Root WebApplicationContext: initialization completed in 1182 ms
[0m[0m15:13:04,189 INFO  [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/sduca]] (ServerService Thread Pool -- 219) Initializing Spring FrameworkServlet 'dispatcher'
[0m[0m15:13:04,189 INFO  [org.springframework.web.servlet.DispatcherServlet] (ServerService Thread Pool -- 219) FrameworkServlet 'dispatcher': initialization started
[0m[0m15:13:04,191 INFO  [org.springframework.web.context.support.AnnotationConfigWebApplicationContext] (ServerService Thread Pool -- 219) Refreshing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Thu Aug 30 15:13:04 CEST 2018]; parent: Root WebApplicationContext
[0m[0m15:13:04,192 INFO  [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] (ServerService Thread Pool -- 219) JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
[0m[0m15:13:04,220 INFO  [org.springframework.web.servlet.DispatcherServlet] (ServerService Thread Pool -- 219) FrameworkServlet 'dispatcher': initialization completed in 31 ms
[0m[0m15:13:04,239 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 1) JBAS018559: Deployed "sduca-consumer-listener-1.0-SNAPSHOT.war" (runtime-name : "sduca-consumer-listener-1.0-SNAPSHOT.war")

这是pom.xml

<?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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>sduca-consumer-listener</groupId>
    <artifactId>sduca-consumer-listener</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <build>
        <sourceDirectory>src</sourceDirectory>
        <!-- Telling to use jdk 1.7 -->
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.0</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <!-- I am not using web.xml -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <webappDirectory>/sduca</webappDirectory>
                </configuration>
            </plugin>

        </plugins>
    </build>

    <dependencies>
        <!-- Using Spring 4 because of jdk 1.7 -->
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.3.18.RELEASE</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.9.6</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/log4j/log4j -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>

    </dependencies>


</project>

这个是src / main / webapp / WEB-INF / jboss-web.xml的内容

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
    <context-root>sduca</context-root>
</jboss-web>

有三个班级。 AppInitializer.java / *这个类配置某些东西的servlet * / package com.hpe.oss.eventhandler.sduca.receiver.config;

import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer{
    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[]{ AppConfig.class };
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return null;
    }

    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }
}

app config.Java

/*
This class is just for configuration and replace web.xml
Which is an old way of configuring I guess
 */

package com.hpe.oss.eventhandler.sduca.receiver.config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.hpe.oss.eventhandler.sduca.receiver")
public class AppConfig {
}

和控制器:OSSreceiver.java

package com.hpe.oss.eventhandler.sduca.receiver;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
public class OSSreceiver {

    @RequestMapping(value="/OSSreceiver", method = RequestMethod.POST)
    public @ResponseBody String postResponse()
    {
        return "hello";
    }
}
答案

更改映射到/*/sduca/*

  @Override
  protected String[] getServletMappings() {
    return new String[]{"/*"};
  }

以上是关于使用JBoss部署REST服务时出现问题的主要内容,如果未能解决你的问题,请参考以下文章

将 GWT 部署到 JBoss 时出现 web.xml 问题

Springboot 与 RestEasy 集成并部署到 Jboss 服务器

Jenkins 使用 Deploy to Container 插件部署到 JBoss EAP7

java.lang.UnsatisfiedLinkError 在 teiid jboss 翻译器开发中从 FesApi 创建 EpcDocument 对象时出现异常

从 Jersey REST 客户端调用时出现 405 错误代码

JBoss Tools部署错误:这可能是由于服务器的临时部署目录位于与最终目标不同的文件系统上