IDEA builds Spring Boot project

What is Spring Boot

Spring Boot is a new framework provided by the Pivotal team, which is designed to simplify the initial construction and development process of new spring applications. The framework uses a specific way to configure, so that developers no longer need to define a templated configuration. In this way, Spring Boot is committed to becoming a leader in the booming area of rapid application development

benefit

  1. Independent Spring applications can be created, and executable JARs and WARs can be created based on their Maven or Gradle plug-ins;
  2. Embedded Servlet containers such as Tomcat or Jetty;
  3. Provide automatically configured "starter" project object model (POMS) to simplify Maven configuration;
  4. Configure the Spring container as automatically as possible;
  5. Provide ready features such as metrics, health checks, and external configurations;
  6. Absolutely no code generation, no XML configuration required.

build

Environment and tools: JDK 1.8, Maven 3.0 +, IntelliJIDEA2018 (it is recommended to use idea to build and learn springboot, and idea is very friendly to audit and generate springboot)

Step 1: idea – file – new file – project; then select Next

Next: select project information; select next

Next: add support, select web, and click Next

Next: select the project name, click finish to complete the build, and wait for maven to add the required dependency package

pom file maven dependency

<?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>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.15.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.springboot</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <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>

The start class of springboot, from which the project starts without tomcat configuration

Create a new controller
stay DemoApplication.class The new package or class will take effect

Use * * @ restcontroller in HellowController** ,@RestController=@Controller+@ResponseBody
Is returned in json format

Then start the project:

And the default port of tomcat embedded in springboot is 8080:

The replacement port needs to be application.properties Configure; and springboot supports the yml file format
application.properties : (the properties file is written in the form of '.' points.)

application.yml : (the YML file is written in the format of ':' colon)

Default port: 8080
Change port: 8888

Start successfully! The springboot demo is complete. Springboot perfectly solves the requirements of various configuration files of spring before; it can be completed step by step. Chicken and vegetable peck at each other. Don't spray.

1. Blog content and form
This blog is a personal blog, which does not involve commercial use, only provides learning reference, and the content comes from personal original as well as Internet reprint and excerpt.
2. Copyright notice
Articles, pictures and documents with original logo on this blog shall not be used for commercial purposes or traditional media without my permission. Internet media or personal reprint please indicate the source and link, otherwise it is an infringement.

Never ask Qingfeng

Keywords: Spring Maven SpringBoot Tomcat

Added by phpfreakjav on Tue, 16 Jun 2020 07:11:02 +0300