SpringBoot2.0之一 使用eclipse创建springboot项目

1、安装sts工具

Help -> Eclipse Marketplace…

Search或选择“Popular”标签,选择Spring Tool Suite (STS) for Eclipse插件,安装

2、new project ,选择spring -> spring starter project

这里写图片描述

3、按自己的信息填写,我这里项目名叫demo-2

这里写图片描述

4、选择版本和组件

这里写图片描述
我这里选了1.5.10版本,选了mysql和web,因为是web项目,都会选择web这个选项,其他的可以按自己需要选择,点击 Finish ,就会有一个新项目,不过需要等待几分钟,sts工具会生成spring boot目录的结构及文件

5、可以看到,项目结构已经生成完毕

这里写图片描述

6、查看pom.xml文件

这里写图片描述
发现里面有两个依赖,就是刚刚我们选择的web和mysql, 这里就加入了对应的依赖包,所以上面的选择,只是在这里加入依赖而已。

7、写一个自己的Controller测试

@RestController
public class TestController {

    @RequestMapping("/hello1")
    public String test(){
        return "hello,this is a springboot demo";  
    }
}
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

这里用了@RestController进行测试,也可以写@Controller,写自己的页面

8、运行spring-boot的入口文件Demo2Application.java

@SpringBootApplication
public class Demo2Application {

    public static void main(String[] args) {
        SpringApplication.run(Demo2Application.class, args);
    }
}
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

这里写图片描述
启动成功

9、直接在浏览器访问

这里写图片描述

10、注意目录结构

这里写图片描述

application文件,必须在所有包的上面,也就是说,其他的包,需要是application文件所在包的子包

11、常见问题

  1. start.spring.io 不能访问:https://blog.csdn.net/qq_21727627/article/details/78675127
  2. Failed to configure a DataSource:https://blog.csdn.net/u010448530/article/details/80840828
  3. SocketTimeoutException: connect timed out:https://blog.csdn.net/u011389297/article/details/79892320
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值