第二章 springboot项目创建

万丈高楼平地起,先创建springboot + maven管理项目

使用idea,new project,选择快速maven模板创建:

输入groupId和artifactId之后,直接next到结束,基础项目就创建好了

pom文件引入springboot依赖:

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

Spring-boot-starter-parent是一个特殊的starter,用来提供相关的maven默认依赖,使用之后,常用的包依赖可以省略version标签

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

这是web支持的starter,最后添加springboot的编译插件:

<build>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

打开app主类,添加注解@SpringBootApplication,开启自动配置

扫描二维码关注公众号,回复: 6021362 查看本文章

新建springboot启动器,选择main class为app主类:

启动:修改主动类main函数代码为:

SpringApplication.run(App.class, args);

点右上角的三角符号启动即可。

至此,springboot基础项目创建完毕

猜你喜欢

转载自blog.csdn.net/mrxiky/article/details/86536786
今日推荐