springBoot application on Jboss EAP, servlet context not lodaed

谁说我不能喝 提交于 2020-03-13 05:11:31

问题


I have a very simple spring boot application that I want to deploy to Jboss EAP. Here is my simple application class:

@SpringBootApplication

public class MayurApplication extends SpringBootServletInitializer{

    public static void main(String[] args) {
        SpringApplication.run(MayurApplication.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(applicationClass);
    }

    private static Class<MayurApplication> applicationClass = MayurApplication.class;
}

@RestController
class GreetingController {

    @RequestMapping("/hello/{name}")
    String hello(@PathVariable String name) {
        return "Hello, " + name + "!";
    }
}

and my pom.xml is also very basic. When I run this application on Tomcat, using the embedded Tomcat what ships with spring boot. Everything works like charm in just one click. I can access http://localhost:8080/demo/hello/World and it works too.

Now I tried to make it Jboss EAP compatible war, I disabled the Tomcat by excluding from spring-boot-starter-web, and convert it into a war project. (as suggested by article http://spring.io/blog/2014/03/07/deploying-spring-boot-applications).

I also added:

<dependency>
                  <groupId>javax.servlet</groupId>
                  <artifactId>javax.servlet-api</artifactId>
                 <scope>provided</scope>
            </dependency>,

as it was complaining.

Now after all this, it compiles fine and creates a war too. When I copied this war to jboss deployment, I can see it successfully deployed on console. But the rest api http://localhost:8080/demo/hello/World just does not work and constantly throws error on browser:

JBWEB000068: message /demo/hello/World
JBWEB000069: description JBWEB000124: The requested resource is not available.

What am I doing wrong?


回答1:


Found this in Spring Boot Reference Guide, add the below line in application.properties file

server.servlet-path=/*

tested this in jBoss EAP 6.2 and worked fine.




回答2:


Answer is here : Spring Java Config vs Jboss 7

Apparently "/" does not work on Jboss EAP 6.3 , but "/*" works. and they seems to have fixed it with wildfly 8




回答3:


You mentioned JBoss 6 in you tags. Based on my experience Spring Boot Autoconfigure and JBoss 6 (specifically) is a no-go. If Hot Deploy is turned on or perhaps some other condition JBoss VFS performs some aggressive scanning of all jars in the war file. Once it starts to scan the classes in the autoconfigure module, it will abort due to an error akin to ClassNotFoundException. If you are using Autoconfigure, one solution might be to place the spring modules in the Container's lib. But this would make deployment unwieldy. I did not see this behavior on JBoss 7 nor Wildfly 8.



来源:https://stackoverflow.com/questions/27576629/springboot-application-on-jboss-eap-servlet-context-not-lodaed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!