【SpringBoot】0. 使用maven的方式创建helloworld项目

课堂笔记:

0. 引入Springboot的parent包,引入Springboot的starter-web包

在Spring官网中,使用快捷工具生成一个HelloWord项目 Spring Initializr

参照这个项目,在IDEA中创建一个新的项目,并配置maven的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>
    <!--Springframe:集成了框架所需要的所有第三方依赖。只有加了这个之后,才能将项目标记成springboot项目-->
    <!--spring-boot-starter-parent中又引入了spring-boot-dependencies包,其中定义了Springboot框架所需的第三方包及版本号,
    避免了版本冲突。版本配置的依据来自SpringBooy的版本仲裁中心-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <groupId>cn.xueyuan.springboot</groupId>
    <artifactId>helloworld</artifactId>
    <version>1.0-SNAPSHOT</version>

    <!--开发web应用的依赖-->
    <!--starter叫做场景启动器,Spring提供了非常多的启动器。
    不同的场景启动器维护了所对应的所有依赖,从而简化了maven pom的书写
    https://docs.spring.io/spring-boot/docs/2.3.5.RELEASE/reference/html/using-spring-boot.html#using-boot-starter
    spring-boot-starter-web:
    Starter for building web, including RESTful, applications using Spring MVC. Uses Tomcat as the default embedded container
    -->
    <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>
            <!--部署Springboot的插件,没有这个插件,导出的helloworld.jar包无法通过java -jar进行运行。
            加了该插件后 打包的jar包中,MANIFEST.MF文件中才会指定Start-Class: cn.tulingxueyuan.Application-->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.3.5.RELEASE</version>
            </plugin>
        </plugins>
    </build>

</project>

1. 创建Controller

2. 创建启动类Application

启动项目,并测试:localhost:8080/hello/world

3. 创建配置文件Application.properties,手动修改servlet相关配置

4. 打包HelloWorld项目并部署

 通过java -jar运行,则自动部署Springboot项目成功

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值