搭建第一个SpringBoot项目

搭建第一个SpringBoot项目

1.准备工作

  • 1.新建 Spring Initializr 项目
    在这里插入图片描述
  • 2.选择 Spring Initializr
  • 3.选择 SDK,点击【new】这里使用 JAVA SDK 要求版本 1.8+,选择你JDK安装的路径
  • 4.然后选择默认的 url-> Next

在这里插入图片描述

  • 5.填写一下项目的信息
    在这里插入图片描述
  • 6.根据需求勾选依赖
    在这里插入图片描述
    在这里插入图片描述
  • 7.选择好项目的位置,->Finish
    在这里插入图片描述
  • 8.如果是第一次配置 Spring Boot 的话,需要等待一会儿 IDEA 下载相应的依赖包,默认创建好的项目结构如下:
    在这里插入图片描述
SpringBoot项目,少了很多配置文件。默认生成的有:

    SpringbootApplication: 一个带有 main() 方法的类,用于启动应用程序
    SpringbootApplicationTests:一个空的 Junit 测试了,它加载了一个使用 Spring Boot 字典配置功能的 Spring 应用程序上下文
    application.properties:一个空的 properties 文件,可以根据需要添加配置属性
    pom.xml: Maven 构建说明文件

2.真正项目(HelloController)

  • 1.在 main/java/com.sxy.springboot包下新建一个类HelloController
    在这里插入图片描述
  • 2.写简单的类内容
    在这里插入图片描述
  • 3.利用 IDEA 启动 Spring Boot(会提示maven导包,点击Import Changes
  • 4.运行提示信息
    在这里插入图片描述
    我们之所以在上面的项目中没有手动的去配置 Tomcat 服务器,是因为 Spring Boot 内置了 Tomcat


出错原因见另一篇文章运行springboot找不到数据源的问题

运行后我的demo出现了问题,提示如下:(没有遇到这个问题的宝宝直接跳过这一步)
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-09-27 09:14:13.402 ERROR 13440 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class


Action:

Consider the following:
	If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
	If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).


Process finished with exit code 1


  • 5.运行结果(在浏览器的地址栏输入访问路径)
    在这里插入图片描述
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值