新手--请教tomcat(spring-boot)问题

吃不胖的茶叶蛋 2016-08-20 11:02:37
用maven构建spring-boot项目,运行时main提示tomcat已启动,但是我在浏览器里访问localhost:8080/ 却是404错误,why?

基础代码:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@EnableAutoConfiguration
public class Application {
@RequestMapping("/")
public String home() {
return "<html><head><title>Hello World!</title></head><body><h1>Hello World!</h1><p>This is my first web site</p></body></html>";
}

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



console结果:

. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.4.0.RELEASE)

2016-08-20 10:54:16.103 INFO 5552 --- [ main] Application : Starting Application on DESKTOP-78CSS9B with PID 5552 (E:\workspace\javaEE\first-spring-boot\target\classes started by twx in E:\workspace\javaEE\first-spring-boot)
2016-08-20 10:54:16.107 INFO 5552 --- [ main] Application : No active profile set, falling back to default profiles: default
2016-08-20 10:54:16.140 INFO 5552 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@768b970c: startup date [Sat Aug 20 10:54:16 CST 2016]; root of context hierarchy
2016-08-20 10:54:17.146 INFO 5552 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2016-08-20 10:54:17.157 INFO 5552 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2016-08-20 10:54:17.158 INFO 5552 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.4
2016-08-20 10:54:17.231 INFO 5552 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2016-08-20 10:54:17.231 INFO 5552 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1094 ms
2016-08-20 10:54:17.267 INFO 5552 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2016-08-20 10:54:17.541 INFO 5552 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2016-08-20 10:54:17.595 INFO 5552 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2016-08-20 10:54:17.600 INFO 5552 --- [ main] Application : Started Application in 1.716 seconds (JVM running for 2.031)
...全文
2060 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
田间石 2017-04-01
  • 打赏
  • 举报
回复
项目需要是web项目,不然要手动去配置。
zzddcyy 2016-11-29
  • 打赏
  • 举报
回复
如果我没猜错的话,你少加了个jar包,spring-webmvc这个包
  • 打赏
  • 举报
回复
引用 2 楼 FS1360472174 的回复:
测试过代码,贴出来的那段代码肯定没问题。 可以先看下启动详细日志。有没有warning,error之类。 如果仍然找不到错误,建议在这个repo 基础上测试 https://github.com/spring-guides/gs-spring-boot
问题的原因在于jar包。可能是因为之前网络不好,从maven仓库下载下来的spring核心jar包不完整,删掉重新下载就好了
xams-creator 2016-08-23
  • 打赏
  • 举报
回复
return "hello world" 试试
方丈的寺院 2016-08-21
  • 打赏
  • 举报
回复
测试过代码,贴出来的那段代码肯定没问题。

可以先看下启动详细日志。有没有warning,error之类。


如果仍然找不到错误,建议在这个repo 基础上测试
https://github.com/spring-guides/gs-spring-boot


computerclass 2016-08-20
  • 打赏
  • 举报
回复
404 表示找不到相应的网页,是不是spring的配置有问题呀

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧