初始化spring boot中遇到的问题

大兔子大兔子 提交于 2019-11-30 15:47:22

无法连接到localhost:8080

1234
<dependency>   <groupId>org.springframework.boot</groupId>   <artifactId>spring-boot-starter</artifactId></dependency>

pom.xml中的这段代码改成

1234
<dependency>   <groupId>org.springframework.boot</groupId>   <artifactId>spring-boot-starter-web</artifactId></dependency>

spring-boot-starter和spring-boot-starter-web的区别:

  • spring-boot-starter 是Spring Boot的核心启动器,包含了自动配置、日志和YAML
  • spring-boot-starter-web 支持全栈式Web开发,包括Tomcat和spring-webmvc

相关参考

Spring Boot的启动器Starter详解

访问localhost:8080时出现Whitelabel Error Page

需要输入在类中输入注解@RequestMapping("/")来映射地址,为了使用@RequestMapping("/"),必须在头部导入org.springframework.web.bind.annotation.RequestMapping包。

@RestController注解等价于@Controller+@ResponseBody的结合,使用这个注解的类里面的方法都以json格式输出,必须在头部导入import org.springframework.web.bind.annotation.RestController包。

若未导入包前已启动项目,需要用maven reimport更新依赖包,不然会报错。

原文:大专栏  初始化spring boot中遇到的问题


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!