SpringBoot [ 1.快速启动 ]

SpringBoot [ 1.快速入门 ] - 目录


1.Maven项目构建

1.1构建Maven项目

使用编译器构建Maven项目,此处略.

1.2.引入POM依赖

<!-- 全局常量 -->
<properties>
    <!-- SpringBoot -->
    <spring.boot.version>2.1.4.RELEASE</spring.boot.version>
</properties>

<dependencies>
    <!-- SpringBoot Web -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>


<!-- 依赖统一管理 -->
<dependencyManagement>
    <dependencies>
        <!-- Spring Boot -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>${spring.boot.version}</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>
    </dependencies>
</dependencyManagement>

    <build>
        <!-- 插件 -->
        <plugins>
            <!-- 打包插件 -->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.1.4.RELEASE</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>com.mantou.boot.ManTouSpringBootApplication</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>

可是为什么需要spring-boot-starter-web呢?我们看一下项目的依赖就明白了.

在这里插入图片描述
我们可以看的spring-boot-starter, web,tomcat都在这个依赖下,特别是spring-boot内嵌的tomcat在该依赖下,所以该依赖是必要的.

3.启动类配置

/**
 * SpringBoot 启动类
 * @author mantou
 */
@SpringBootApplication
public class ManTouBootApplication {

    public static void main(String[] args) {
        SpringApplication.run(ManTouBootApplication.class, args);
    }
}

4.配置文件

4.1.基本配置文件

  • application.yml / application.properties
    (SpringBoot配置文件,可使用yml文件或者properties文件; 个人推荐使用yml文件,支持多种写法,可读性强)

4.2.基本配置内容

application.yml

server:
  # 端口
  port: 8888
  servlet:
    # 项目访问前缀
    context-path: /m-boot

4.4.多环境配置

在真实开发的时候,项目大多使用多环境配置,用于区分各种环境(测试,生成,本地…),如图下:

在这里插入图片描述
当使用多环境配置的时候,就要在主配置文件(application.yml)中选择使用的配置文件,如下:

server:
  # 端口
  port: 8888
  servlet:
    # 项目访问前缀
    context-path: /m-boot
    
spring:
  profiles:
    # 选择活动的配置文件
    active: dev

5.启动服务

如果编译器用的是idea,在微服务多的时候可以打开idea的RunDashboard进行服务操作(具体使用请百度)

在这里插入图片描述

5.1.1查看日志

控制台日志如下即启动成功
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值