1. 问题描述

springboot的面世,成为Java开发者的一大福音,大大提升了开发的效率,其实springboot只是在maven的基础上,对已有的maven gav进行了封装而已,今天用最简单的代码快速入门springboot。

2. 解决方案

强烈推荐大家使用Idea的付费版(破解感谢下蓝宇),Idea对maven、git等插件支持的更加好。

使用idea自带的spring Initializr(实际调用的是springboot的官网上的initializr),快速新建springboot项目。

2.1 新建Springboot项目

(1)file->new->project

(2)点击next(第一个)

创建springboot项目(因为连接的国外的网站,next有时会几秒的延迟),将两个值改成自己的配置,Group:com.laowang ,Artifact:sptest,其他可以不用动,点击ok

(3)点击next(第二个)

选择web-》spring web starter

(4)点击next(第三个)

不用做修改,直接finish

新建springboot项目已经完成。

2.2 springboot默认生成三个文件

默认生成的三个文件

2.2.1. pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.laowang</groupId>
<artifactId>sptest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>sptest</name>
<description>Demo project for Spring Boot</description> <properties>
<java.version>1.8</java.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> </project>

重点就一个gav:spring-boot-starter-web,其他可以删除。

2.2.2 application.properties

该文件默认为空,springboot的默认启动端口号:8080,可以在改文件修改。

2.2.3 启动类文件(SptestApplication.java)
package com.laowang.sptest;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication
public class SptestApplication { public static void main(String[] args) {
SpringApplication.run(SptestApplication.class, args);
} }

重点是标签:@SpringBootApplication

2.3 验证springboot

在com.laowang.sptest报下新建ctroller包,并新建类:HelloController

package com.laowang.sptest.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import java.util.HashMap; @Controller
public class HelloController { @RequestMapping("/")
@ResponseBody
public String getHello() {
return "hello";
}
}

执行效果:

服务正常启动。

2.4 重点说明

需要说明两点:

(1)类文件要放在跟启动类同级或者下一目录下,本项目为:com.laowang.sptest包下面。因为springboot默认扫描加载启动类同级或者下级目录的标签类(@RestController,@Service ,@Configuraion,@Component等),假如真需要加载其他目录的标签类,可以通过在启动上配置标签@ComponentScan(具体包)来进行扫描加载。

(2)资源文件默认放到resources下面,templates默认放的是动态文件,比如:html文件,不过要搭配thymeleaf 使用(pom文件中需新加gav)。

其他也没什么了,springboot主要是通过spring提供的多个starter和一些默认约定,实现项目的快速搭建。


I’m 「软件老王」,如果觉得还可以的话,关注下呗,后续更新秒知!欢迎讨论区、同名公众号留言交流!

springboot项目快速构建的更多相关文章

  1. IDEA中SpringBoot项目快速创建单元测试

    如何在IDEA中对于SpringBoot项目快速创建单元测试 创建测试用例 右键需要进行测试的方法,选择GO TO然后选择Test 点击Create New Test 勾选需要创建单元测试的方法 然后 ...

  2. SpringBoot项目快速启动停止脚本

    SpringBoot项目快速启动停止脚本 1.在jar包同级目录下,创建 app.sh #!/bin/bash appName=`ls|grep .jar$` if [ -z $appName ] t ...

  3. springboot:快速构建一个springboot项目

    前言: springboot作为springcloud的基础,springboot的热度一直很高,所以就有了这个springboot系列,花些时间来了解和学习为自己做技术储备,以备不时之需[手动滑稽] ...

  4. SpringBoot系列——快速构建项目

    前言 springboot官方参考指南:https://docs.spring.io/spring-boot/docs/2.1.0.RELEASE/reference/htmlsingle/ Spri ...

  5. 【spring-boot】快速构建spring-boot微框架

    spring-boot是一个快速构建环境的一套框架,其设计理念是尽可能的减少xml的配置,用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义 ...

  6. VUE项目快速构建

    IDE  :VScode 1.新建项目文件夹 ctrl+~   调出命令板,/IDE找到当前文件夹右键 点击‘在命令提示符中打开’ 安装 node:官网(https://nodejs.org/en/d ...

  7. springboot项目快速搭建

    1. 问题描述 springboot的面世,成为Java开发者的一大福音,大大提升了开发的效率,其实springboot只是在maven的基础上,对已有的maven gav进行了封装而已,今天用最简单 ...

  8. springboot+maven快速构建项目

    最近公司运用springboot构建项目,确实比ssh搭建要快很多.springboot官方学习网站 1.首先要下载maven,用maven管理项目很方便,下载完maven配置好环境,maven我就不 ...

  9. 《SpringBoot揭秘 快速构建微服务体系》读后感(五)

    应用日志和spring-boot-starter-logging 快速web应用开发与spring-boot-starter-web 1.项目结构层面的约定

随机推荐

  1. Ruby已经慢慢走向衰退了,那些年代久远而且小众的语言没有翻身的可能性

    Ruby已经慢慢走向衰退了,现在WEB开发里,NODE.JS+前端各种框架是主流,PHP.ruby.Asp.net.python等语言在网站编程方面只会越来越少.数据领域方面,机器学习和人工智能中,p ...

  2. 如何把zip文件直接解压到内存里?

    解压到硬盘再读进来耽误时间. var  LZip: TZipFile;  LMem: TMemoryStream;  LBytes: TBytes;begin  LZip := TZipFile.Cr ...

  3. SharePoint js操作原生的New/Edit表单

    列表的表单,有个类似的需求:在New需隐藏特定字段,Edit时显示. 默认是New/Edit表单的字段是一样,就算在Content type 是隐藏也是同时影响两个表单.   如何做到仅仅在New时隐 ...

  4. TCanvas 类属性及方法

    delphi TCanvas类 类关系   TObject-> TPersistent   对那些作图对象,可使用TCanvas对象作为画布.标准的window控件,例如编辑控件和列表框控件,当 ...

  5. CheckSynchronize实现的不必要的复杂

    在system.classes单元中,CheckSynchronize在ThreadLock上持续调用TMonitor的Exit和Enter以保护SyncList. 因为代码做的第一件事是换出Sync ...

  6. 有效地查找SAP增强点

    找SAP增强点一直都是SAP开发的重点难点,增强开发的代码一般不会很多,但是需要花费比较多的时间在查找增强点上 网上也流传了很多查找SAP增强的方法: 1.利用TCODE寻找增强 2.利用系统函数寻找 ...

  7. SQL 游标知识整理

    游标声明格: declare 游标名称 cursor (游标关键字) for 游标操作对象(select * from 表名称)游标使用: open 游标名称; fetch first from 游标 ...

  8. python中的while循环,格式化输出,运算符,编码

    一.while循环 1.1语法 while 条件: 代码块(循环体) else: 当上面的条件为假的的时候,才会执行. 执行顺序:先判断条件是否为真,如果是真的,执行循环体,再次判断条件,直到条件不成 ...

  9. 【Aizu - ALDS1_1_C】Prime Numbers(素数筛法)

    Prime Numbers  Descriptions: A prime number is a natural number which has exactly two distinct natur ...

  10. C# 设计模式,工厂方法

    C#工厂方法 using System; using System.Collections.Generic; using System.Linq; using System.Text; using S ...