Crazy God said that day1: idea2019.3.2+maven set up springboot project

Posted by willc on Wed, 12 Feb 2020 11:41:54 +0100

Catalog

1.idea configures maven warehouse (alicloud image)

2. Use IDEA to quickly build springboot project

1. Select project construction method: default to go to official website.

2. Fill in project information

3. Select dependent components

4. Project name and project path

3. Running the spring boot project in IDEA

1. Project structure

2.pom.xml file

3. Write controller

4. operation

5. Check whether the console is started successfully

6. Browser window access

4. Package the Spring Boot project and run it through the command window

1. Package with IDEA

2. Use command window to execute jar package

3. Browser window access

1.idea configures maven warehouse (alicloud image)

Reference documents: https://www.jianshu.com/p/0b25a47560a9

Instead of downloading maven separately, I used maven integrated in idea2019.3.2. Other steps are the same as the reference documents.

Why do you want to use Alibaba cloud image? If you do not configure the alicloud image, it will take a lot of time to download maven dependency from the central warehouse by default, so I choose to use the alicloud image to download dependency, and soon all the dependencies can be downloaded.

2. Use IDEA to quickly build springboot project

Reference documents: https://www.cnblogs.com/hellokuangshen/p/11255967.html

Pop up window after file - > New - > Project

1. Select project construction method: default to go to official website.

Or go to the official website https://start.spring.io The compressed package is generated and then imported into Idea.

2. Fill in project information

3. Select dependent components

4. Project name and project path

3. Running the spring boot project in IDEA

1. Project structure

2.pom.xml file

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <!--Part I: Inheritance spring-boot-starter-parent Dependency management, version control and packaging-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <!--Part II: basic elements-->
    <groupId>com.example</groupId>
    <artifactId>demo0211</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo0211</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <!--Part three: Project dependence-->
    <dependencies>
        <!-- web Dependency: Integration tomcat,dispatcherservlet,xml etc.-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!--unit testing-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <!--The fourth part: build configuration.
        Default use spring-boot-maven-plugin,Coordination spring-boot-starter-parent You can take it. Spring Boot Package the project into Jar To run
    -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

3. Write controller

package com.example.demo0211.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    @RequestMapping("/demo1")
    public String demo1(){
        return "hello demo";
    }

}

4. operation

5. Check whether the console is started successfully

6. Browser window access

Returns the string returned in the HelloController.java file to represent success.

4. Package the Spring Boot project and run it through the command window

1. Package with IDEA

2. Use command window to execute jar package

Command: java -jar (package address) d: \ idea \ workspace \ demo0211 \ target \ demo0211-0.0.1-snapshot.jar

The comparison shows that the jar package executed by the command window is the same as that displayed in the console after running in IDEA.

3. Browser window access

4. Other configurations

1. Modify port number

2. Customize the startup picture

Website: https://www.bootschool.net/ascii-art/art-and-design

Published 3 original articles, won praise 0, visited 15
Private letter follow

Topics: Spring Maven xml Java