Eclipse Maven project will turn into SpringBoot project

一、File ——》New ——》Maven Project

 Second, create a directory structure maven web project are as follows:

Third, there will be a mistake: jsp error.

 Fourth, here we do not control this error directly jsp files deleted, you can not being given (because currently I am using a front-end thymeleaf, use html page, so do not jsp), the other, the webapp folder of the web. xml file is deleted, the effect is as follows:

 Fifth, modify pom.xml file, delete all the dependencies (dependencies) and build the label.

Results are as follows:

Sixth, Baidu search springboot, casually looking for an example, copy the contents of the pom.xml (Add Parent dependent, set the encoding format and JDK version, web project dependencies, test dependent (delete), maven compiler plugin)

复制代码
<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
        <relativePath/>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <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>
复制代码

 

 七、添加内容后,完整的pom.xml文件,springboot的版本根据自己的版本使用即可(这是选择maven转springboot工程的最大好处,否则改版本很麻烦,尤其的网速慢的情况下,因为直接新建springboot项目,过一段时间,springboot的版本就更新了,这样会在本地仓库下载很多版本的springboot的jar),我这里就选用1.5.17.RELEASE版本(因为仓库已经下载好了)。

  添加以后,一定要实用Maven->Update Project命令,更新一下工程,否则会一直提示有错,让你更新工程。

 

复制代码
<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>cn.com.winson.springboot</groupId>
    <artifactId>maven-springboot</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.17.RELEASE</version>
        <relativePath />
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <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>
复制代码

 八、这时你再看工程目录结构:工程名后面多了一个【boot】,证明这已经是一个springboot工程了。

九、新建一些目录结构,增加src/main/java和src/test/java目录,方法:项目右键 --> buildPath configure Build Path --> 点击选项卡Libraries --> 选中JRE System Libraries --> 点击edit --> 选中Alternate JRE --> 选择jdk -->点击finish,点击OK,自动出现src/main/java和src/test/java;再手动新建static 和 templates 这俩个文件夹。

如下:这样相当于直接新建springboot工程的目录结构了,但是还少一个application.properties文件,该文件是SpringBoot的核心配置文件,右图即为完整目录。

     SpringBoot完整目录结构:              

 

 

 

十、虽然是SpringBoot工程,但是需要一个工程启动入口,即上图目录结构中的Application.java入口类:

复制代码
package cn.com.winson;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {

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

}
复制代码

 十二、启动工程

 

十三、以上就是通过eclipse新建一个maven工程然后转成SpringBoot工程的完全过程。过程虽然简单,但是容易忘,特意记下,代码可以直接复用。

新建SpringBoot工程的时候,推荐这种方法,因为SpringBoot版本总是更新,公司可能对版本有要求,这样就用这种方法新建,可以避免总是下载SpringBoot的jar。

Guess you like

Origin www.cnblogs.com/morganlin/p/12151735.html