Spring boot return error 404 in Jboss

abdelmouheimen :

I have a sample Spring boot application. It works in Tomcat server but when i generate a war and deploy it in jboss server(7.1.1) i have 404 error.

this is my restController example :

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloWorldController {
   @RequestMapping(value="/test")
   public String sayHello() {
      return "Hello Spring Boot!!";
   }
}

and this is my main class :

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;

@SpringBootApplication
public class MainApp extends SpringBootServletInitializer {
   public static void main(String[] args) {
      SpringApplication.run(MainApp.class, args);
   }
   @Override
   protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
   return application.sources(MainApp.class);
   }
}

i added an application.properties file and i added in it this line :

server.contextPath = /*

my jbos-web.xml is like this :

> <?xml version="1.0" encoding="UTF-8"?> <!--   this is really not
> needed...   you can just build (or rename WAR file to)
> spring-boot-jboss.war
> --> <!DOCTYPE jboss-web> <jboss-web>   <context-root>/test</context-root> </jboss-web>

and finally my pom.xml is as follow :

<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.boraji.tutorial.springboot</groupId>
    <artifactId>spring-boot-hello-world-example</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <properties>
        <java.version>1.7</java.version>
    </properties>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.4.RELEASE</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

i run the applciation by using this url : http://localhost:8080/test/test but a 404 error was returned.

Thank you for your help.

Sebastien :

I had the same problem on JBoss EAP 6.4 / spring boot 1.5 and what fixed it was to add this property

server.servlet-path=/*

as explained in this post : Deploying spring boot on JBOSS EAP 6.1

It worked fine without this property on JBoss EAP 7.1 though.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=99908&siteId=1