Abh*_*bhi 5 http-status-code-404 wildfly spring-boot
您好,我正在尝试使用 Eclipse 通过一个非常简单的应用程序来学习 Wildfly 和 springboot。项目名称是 springboot-test。包括主方法类在内的所有类都在同一个包中。
Main 方法类称为“App”,其代码如下:
@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();
}
}
Run Code Online (Sandbox Code Playgroud)
以下是服务器日志:
11:36:57,281 信息 [org.wildfly.extension.undertow](ServerService 线程池 - 68)WFLYUT0021:已注册的 Web 上下文:服务器“default-server”的“/springboot-test-0.0.1-SNAPSHOT”
11:36:57,301 信息 [org.jboss.as.server](ServerService 线程池 - 37)WFLYSRV0010:部署了“springboot-test-0.0.1-SNAPSHOT.war”(运行时名称:“springboot-test-0.0” .1-SNAPSHOT.war")
11:36:57,408 信息 [org.jboss.as.server](控制器引导线程)WFLYSRV0212:恢复服务器
11:36:57,411 INFO [org.jboss.as](控制器启动线程)WFLYSRV0060:Http 管理接口监听http://127.0.0.1:8181/management
11:36:57,412 INFO [org.jboss.as](控制器启动线程)WFLYSRV0051:管理控制台监听http://127.0.0.1:8181
11:36:57,412 INFO [org.jboss.as](控制器启动线程)WFLYSRV0025:WildFly Full 11.0.0.Final(WildFly Core 3.0.8.Final)在 11393 毫秒内启动 - 732 个服务中的 504 个是惰性服务(353 个) ,被动或按需)
由于您使用 wildfly 进行部署,我希望您生成 war 文件,并且服务器日志似乎支持我的声明
你有SpringBootServletInitializer类吗???如果不是,那就是问题所在
你需要这样的东西
@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();
}
}
Run Code Online (Sandbox Code Playgroud)
我不确定注释 @SpringBootApplication和@RestController一堂课是否有任何问题。但我的建议是分开维护
@RestController
public class Mycontroller{
@RequestMapping("/index")
public String sayHello(){
return "hello from spring boot" + this.student.showAddress();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2816 次 |
| 最近记录: |