Spring boot app in WildFly 7 - endpoint not found

24 Views Asked by At

As I started to maintain a legacy app that runs inside JBoss 7x (yep), I try to create a prototype with a modern spring boot stack (2.7 because of JDK 8). I am able to deploy the app as war to JBoss, but invoking a rest controller returns 404 error.

pom.xml

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.7.16</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>demo</name>
<description>demo</description>
<properties>
    <java.version>8</java.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <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>

DemoApplication.java

@ComponentScan
@EnableAutoConfiguration
public class DemoApplication extends SpringBootServletInitializer {
operational-decision-manager-decision-center
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        System.err.println("\n\nCONFIGURE\n\n");
        return application.sources(DemoApplication.class);
    }

src\main\webapp\WEB-INF\jboss-web.xml

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

GreetingController.java

@RestController
public class GreetingController {
    String subject = "World";

    @GetMapping("/greeting")
    public String greeting() {
        return "Hello, " + subject + "!";
    }

    @PostMapping("/subject/{subject}")
    public boolean setSubject(@PathVariable String subject) {
        this.subject = subject;
        return true;
    }
}

$JBOSS_PATH/modules/system/layers/base/jdk/unsupported/main

?xml version="1.0" encoding="UTF-8"?> 
<module xmlns="urn:jboss:module:1.5" name="jdk.unsupported"></module> 

The first finding is that the DemoApplication#configure is never called. And maybe that's why the app sources are not scanned and the controller is not initialized.

When I access http://localhost:4000/demo/greeting, I will receive: BWEB000065: HTTP Status 404 - /demo/greeting

When I access URL outside of the context, it responds with HTTP error 404:

This localhost page can’t be found
No webpage was found for the web address: http://localhost:4000/xyz
HTTP ERROR 404

As you can see, the first response is decorated by JBoss, the latter not. I even tried to add an actuator but its endpoint is not reachable either.

Other questions I reviewed:

PS I receive hundreds of warning like this but I assume that they are harmless

12:56:39,518 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-16) JBAS015852: Could not index class org/springframework/web/servlet/config/annotation/InterceptorRegistry.class at /C:/dev/Lion/JBoss/bin/content/demo-0.0.1-SNAPSHOT.war/WEB-INF/lib/spring-webmvc-5.3.30.jar: java.lang.IllegalStateException: Unknown tag! pos=12 poolCount = 149
    at org.jboss.jandex.Indexer.processConstantPool(Indexer.java:606) [jandex-1.0.3.Final-redhat-2.jar:1.0.3.Final-redhat-2]
0

There are 0 best solutions below