Spring Boot Introduction and Getting Started

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/qq_40646143/article/details/90376607

spring boot Introduction

  • A simplified framework for Spring application development
  • Spring a large integration of the entire technology stack
  • J2ee development of one-stop solution

 

spring boot advantage

  • Spring quickly create stand-alone projects and integrated framework mainstream
  • Use Embedded Servlet container, applications do not need to be labeled as war package
  • dependent automatic starters and Versioning
  • A large number of automatic configuration, simplifying the development, can modify the default values
  • No configuration xml, no code is generated, out of the box
  • Application Monitoring run quasi-production environment when
  • Natural integration with the cloud

 

What is micro-services?

  • martin fowler published articles can understand the connection as follows  https://martinfowler.com/microservices/
  • MicroService short: architectural style (micro-based service) application should be a small group of services that can communicate via HTTP way; each functional element is ultimately an independent unit replacement and software upgrades independently.

 

1, jdk is 1.8, maven repository is 3.6.1

maven java project to modify the compiled version of the way

setting file in the local maven repository add this

<profiles>
    <profile>   
        <id>jdk1.8</id>
        <activation>   
            <activeByDefault>true</activeByDefault>
            <jdk>1.8</jdk>   
        </activation>
        <properties>   
            <maven.compiler.source>1.8</maven.compiler.source>
            <maven.compiler.target>1.8</maven.compiler.target>
            <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
            <encoding>UTF-8</encoding>
        </properties>   
    </profile>
</profiles> 

Note: The default jdk compiled version is 1.5, for example, the code uses the new features jdk1.8, which is the need to use jdk1.8 compiled

 

Then there is of course a hello word

1 of the project to create a maven project

Nothing selected, then the data item name next to complete the final finsh

 

2, was added in dependence spring boot pom

   <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.0.RELEASE</version>
        <relativePath/>
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

3. Create a project started springboot entrance

com.weijie下面创建主程序   HelloWordApplication.java
package com.weijie;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
//标识这个是spring boot 应用
@SpringBootApplication
public class HelloWordApplication {

    public static void main(String[] args) {
        //启动spring boot 入口
        SpringApplication.run(HelloWordApplication.class,args);
    }

}

 

4 Create controller, controller must otherwise inaccessible in the main package

Creating HelloController.java in com.weijie.controller

package com.weijie.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class HelloController {

    @RequestMapping("/hello")
    @ResponseBody
    public String getHello(){
        return "hello word";
    }

}

 

Start program startup main method

The next step is how to package it released

Add 1 pom.xml

  <!--  这个插件可以把项目打成一个可执行jar包  -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

2, compiled into a jar following

 

3, run the following

 

 

4, run the jar

5, in fact, this jar package which contains tomcat, run the following

Guess you like

Origin blog.csdn.net/qq_40646143/article/details/90376607