Getting "404 - Not found" error with Wildfly and springboot
Asked Answered
M

2

6

Hello i am trying to learn wildfly and springboot with a very simple application using eclipse. The project name is springboot-test. All the classes including the main method class are in the same package.

Main method class is called 'App' which has the following code:

 @SpringBootApplication
 @RestController
 public class App {

    @Autowired
    private Student student;

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

    @RequestMapping("/index")
    public String sayHello()
    {
        return "hello from spring boot" + this.student.showAddress();
    }
}

Here are the server logs:

11:36:57,281 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 68) WFLYUT0021: Registered web context: '/springboot-test-0.0.1-SNAPSHOT' for server 'default-server'

11:36:57,301 INFO [org.jboss.as.server] (ServerService Thread Pool -- 37) WFLYSRV0010: Deployed "springboot-test-0.0.1-SNAPSHOT.war" (runtime-name : "springboot-test-0.0.1-SNAPSHOT.war")

11:36:57,408 INFO [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0212: Resuming server

11:36:57,411 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:8181/management

11:36:57,412 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:8181

11:36:57,412 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Full 11.0.0.Final (WildFly Core 3.0.8.Final) started in 11393ms - Started 504 of 732 services (353 services are lazy, passive or on-demand)

Url i am accessing is: http://localhost:8080/springboot-test/index

Macaque answered 9/2, 2018 at 6:44 Comment(5)
Does your project work when run as standalone (I mean, outside of Wildfly, using the default embedded Tomcat instance of a Spring Boot app) ?Blatt
Hello, yes it works fine with embedded tomcat. Then I am simply accessing the page with: localhost:8080/indexMacaque
Did you find a solution to this problem?Agon
Think ,its same issue you are facing https://mcmap.net/q/1915120/-jboss7-undertow-spring-boot-throwing-404Seko
@CharlesMorin I was facing the same issue , this was my problem https://mcmap.net/q/1915120/-jboss7-undertow-spring-boot-throwing-404Seko
S
3

Since you are using wildfly for deployment , I'm hoping you are generating war file and server logs seems to support my statement

Do you have SpringBootServletInitializer class ??? if not that's the issue

You need something like this

@SpringBootApplication
@RestController
public class ServletInitializer extends SpringBootServletInitializer{

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

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

@Override
public void onStartup(ServletContext servletContext) throws ServletException{
    super.onStartup(servletContext);

     }
@RequestMapping("/index")
public String sayHello(){
        return "hello from spring boot" + this.student.showAddress();
    }
}

I' not sure is there any issue in annotating @SpringBootApplicationand @RestController in one class. But my suggestion is to keep it separate for maintenance

@RestController
public class Mycontroller{

  @RequestMapping("/index")
  public String sayHello(){
      return "hello from spring boot" + this.student.showAddress();
  }
}
Seko answered 26/4, 2018 at 8:35 Comment(0)
A
0

Your Server log says:

11:36:57,281 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 68) WFLYUT0021: Registered web context: '/springboot-test-0.0.1-SNAPSHOT' for server 'default-server'

It should be accessible at: http://localhost:8080/springboot-test-0.0.1-SNAPSHOT/index

Configure your Maven file to use <finalName>${project.artifactId}</finalName> if you like to register your address.

Annexation answered 18/6, 2018 at 13:7 Comment(2)
Hello, so does that mean we have to build the project before deploying to the WildFly server?Kandacekandahar
Since WildFly is an application server: yes, normally you deploy packed applications, see: docs.jboss.org/author/display/WFLY/Application+deploymentAnnexation

© 2022 - 2024 — McMap. All rights reserved.