Java - 微服务实战 | Spring Boot 搭建基础系列(第一篇): 初体验

最近在学习spring boot,也查了一些资料进行参考学习,发现spring boot框架真的很好用,现在就开始和小伙伴们动手一起搭建spring boot项目吧!

一.SpringBoot简介

  

Spring Boot makes it easy to create stand-alone, production-grade Spring-based Applications that you can run. We take an opinionated view of the Spring platform and third-party libraries, so that you can get started with minimum fuss. Most Spring Boot applications need very little Spring configuration.

You can use Spring Boot to create Java applications that can be started by using java -jar or more traditional war deployments. We also provide a command line tool that runs “spring scripts”.

Our primary goals are:

  • Provide a radically faster and widely accessible getting-started experience for all Spring development.
  • Be opinionated out of the box but get out of the way quickly as requirements start to diverge from the defaults.
  • Provide a range of non-functional features that are common to large classes of projects (such as embedded servers, security, metrics, health checks, and externalized configuration).
  • Absolutely no code generation and no requirement for XML configuration

上面,是在官网介绍的,其实springboot很好理解,也很好上手。

SpringBoot是Spring家族中一个全新框架,它用来简化Spring应用过程的创建和开发过程,也可以说SpringBoot能简化我们之前采用 SpringMVC + Spring + MyBatis 框架进行的开发过程。SpringBoot使您可以轻松地创建独立的、生产级的、基于Spring的应用程序。我们对Spring平台和第三方库有一个独到的观点,这样您就可以以最少的麻烦开始了。

Springboot的特性:

1).能够创建基于Spring的应用程序。

2).能够直接使用Java main方法内嵌的Tomcat、Jetty服务运行Spring Boot的程序,不需要部署war包文件。

3).提供约定的starter POM简化Maven配置,让Maven的配置变得简单。

4).根据项目的Maven依赖配置,Spring Boot自动配置Spring、SpringMvc。

5).提供程序的健康检查等功能。

6).基本可以完全不使用XML配置文件,采用注解配置。

............说了那么多,一起动手来试试吧

开发环境:

idea:2018.1.4

jdk  :1.8

maven:3.5.3

springboot:最新正式版2.1.2.RELEASE

二.开始项目创建

2.1 首先创建maven父级,这里就不给大家演示了,在父级项目里创建第一个子类 Spring Boot 项目

右键工程->创建model-> 选择spring initialir 如下图:

如图,父级maven项目springboot-parent,然后在父类项目里创建子级maven工程01-springboot-web,点击next

勾选web,点击next,最后点击Finish完成,第一个SpringBoot项目创建好了,是不是so easy

父级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>

    <groupId>com.example.spring</groupId>
    <artifactId>springboot-parent</artifactId>
    <version>1.0.0-SNAPSHOT</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <!-- 属性配置 -->
    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <!-- 测试的起步依赖 -->
        <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>

子类的pom.xml文件:

项目创建目录如下图:

java:是springboot项目main方法启动窗口

resources:

static: 存放静态资源

templates:存放模板页面

application.properties: 配置文件

2.2 在springboot项目中,创建controller类

2.3 运行springboot项目

如下图,证明springboot项目启动成功

访问程序,http://localhost:8080/boot/hello,如下图,访问成功!!!

转载请标明出处:
原文首发于:https://blog.csdn.net/u012978507/article/details/86537143
本文出自Any1992

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值