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

时间:2018-08-30 16:04:37

标签: java rest spring-mvc jboss war

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

由于技术限制,我不得不使用jdk 1.7。 它是用Java,Maven和Spring MVC编码的。

就我所不了解的代码而言,它应该可以正常工作。我成功地部署了这场战争,根据jboss的日志,我认为它正在按我的期望来映射资源。问题是,当我向期望的URI( X.X.X.X:8080 / sduca / OSSreceiver )发送POST请求时,找不到资源。

我真的找不到原因或方式。我以为我从来没有做过这样的事情,但是根据同事的说法,它应该可以工作。可能是什么原因?我错过了什么吗?

对不起,如果我把整个项目放进去(我讨厌这样做),但我认为这是必要的,因为我键入的每一行都可能是白痴。

仍然感谢! :)

我得到的答复

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      * /     包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[]{"/"};
    }
}

AppConfig.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";
    }
}

1 个答案:

答案 0 :(得分:0)

将映射更改为/*/sduca/*

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