Spring Boot 01

Spring Boot  Hello  World:

1 no template to create a maven project

2 springboot its dependencies:

In the spring boot official website document https://docs.spring.io/spring-boot/docs/2.1.9.RELEASE/reference/html/

Found: https: //docs.spring.io/spring-boot/docs/2.1.9.RELEASE/reference/html/getting-started-installing-spring-boot.html#getting-started-maven-installation inside there maven related content dependent

    <!--spring boot的依赖-->
    <!-- Inherit defaults from Spring Boot -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.9.RELEASE</version>
    </parent>

    <!-- Add typical dependencies for a web application -->
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

 Note:

The first relies spring-boot-starter-parent he has a father dependent on spring-boot-dependencies, he will really depend on the version management, so management is subject to depend on him not to write the version number, not by his management naturally written version number. 
Second dependent: spring-boot-starter-web : spring scene initiator. Help us to import components required for the normal operation of the web module.

The spring boot functionality so extracted scene, made a number of starter (starters), just import the starter depend on the relevant scenes in the project will be imported in,
and automatic version management.
Various startup Introduction: https://docs.spring.io/spring-boot/docs/2.1.9.RELEASE/reference/html/using-boot-build-systems.html#using-boot-starter

Preparation of a 3 main categories:

/ ** 
 * @SpringBootApplication: a label for the main class, which is described a spring boot application 
 * / 
@SpringBootApplication 
public class MainApplication { 

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

 This part of the preparation of 4 Controller and SpringMVC as:

@Controller
public class HelloController {

    @RequestMapping("/hello")
    @ResponseBody
    public String hello(){
        return "hello ,spring boot !";
    }
}

 Test 5: Direct run the main program: Enter http: // localhost: 8080 / hello

 

Spring Boot application simplifies deployment, do not hit directly War package, you can add Maven plug-ins, the direct production of a jar file executable, so the server can be installed tomcat server.

    <-! maven plugin: direct production of an executable jar file -> 
    <- - Package Penalty for AS AN Executable jar!> 
    <Build> 
        <plugins> 
            <plugin> 
                <groupId> org.springframework.boot </ the groupId> 
                <the artifactId> Boot-Spring-Maven-plugin </ the artifactId> 
            </ plugin> 
        </ plugins> 
    </ Build>

 

Spring Boot Hello World 2.0: Automatic quickly create a Spring Boot project

1 Select spring Initializr, click next

2 Fill in the information, the next step select the module requires, I just chose the web module

3 next   next

Guess you like

Origin www.cnblogs.com/Lemonades/p/11619492.html