Reputation: 146
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.
Upvotes: 5
Views: 3974
Reputation: 881
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.
Upvotes: 3
Reputation: 31397
I'm not sure what exactly you are trying to achieve by using below property
server.contextPath = /*
But, if you want to have root context path for your application then it has to be some string value instead of astrike (which represents a pattern). And, actually this is not allowed. If I used same property while using tomcat server. Tomcat throws below error while registering web module
2018-08-23 21:26:58.500 ERROR 13612 --- [ost-startStop-1] org.apache.tomcat.util.modeler.Registry : Error registering Tomcat:j2eeType=WebModule,name=//localhost/*,J2EEApplication=none,J2EEServer=none
If you are trying to access url as
http://localhost:8080/test/test
Then, update property file with below
server.contextPath = /test
Otherwise, don't add this property in application.properties file, and you can access
http://localhost:8080/test
Upvotes: 0
Reputation: 459
Add ComponentScan annotation on your MainApp class. Probably your @RestController annotation was not found by spring component scanner
@SpringBootApplication
@ComponentScan(basePackages = {"com.blabla.*"})
public class MainApp extends SpringBootServletInitializer {
...
}
Upvotes: 0
Reputation: 1622
Your jboss-web.xml
should be located in scr/main/webapp/WEB-INF/
then Jboss will use it at the start and use your defined context-root
.
Upvotes: 0