本文介绍了得到"404-未找到". Wildfly和springboot错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试使用eclipse通过一个非常简单的应用程序来学习wildfly和springboot.项目名称是springboot-test.包括main方法类在内的所有类都在同一个包中.

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.

主方法类称为"App",其具有以下代码:

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();
    }
}

这是服务器日志:

11:36:57,301信息[org.jboss.as.server](服务器服务线程池-37)WFLYSRV0010:部署了"springboot-test-0.0.1-SNAPSHOT.war"(运行时名称:"springboot- test-0.0.1-SNAPSHOT.war)

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信息[org.jboss.as.server](控制器引导线程)​​WFLYSRV0212:恢复服务器

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

11:36:57,411信息[org.jboss.as](控制器引导线程)​​WFLYSRV0060:监听 http://127.0.0.1:8181/管理

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信息[org.jboss.as](控制器引导线程)​​WFLYSRV0051:管理控制台正在监听 http ://127.0.0.1:8181

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信息[org.jboss.as](控制器引导线程)​​WFLYSRV0025:WildFly Full 11.0.0.Final(WildFly Core 3.0.8.Final)在11393毫秒内启动-在732个服务中启动504个(353个)服务是懒惰,被动还是按需)

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)

我要访问的网址是: http://localhost:8080/springboot-test/索引

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

推荐答案

由于您使用Wildfly进行部署,因此希望您生成的war文件和服务器日志似乎支持我的声明

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

您是否有 SpringBootServletInitializer 类?如果不是这样的话

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

您需要像这样的东西

@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();
    }
}

我不确定在一类中对@SpringBootApplication@RestController进行注释是否存在任何问题.但是我的建议是将其分开进行维护

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();
  }
}

这篇关于得到"404-未找到". Wildfly和springboot错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 20:35