Getting started with Spring Boot and creating small projects

1. Introduction to Spring Boot

  • A framework to simplify Spring application development.
  • A big integration of the entire Spring technology stack.
  • One-stop solution for J2ee development

2. Microservices

  • Microservices are an architectural style.
  • An application is a set of small services. Intercommunication can be carried out through http.
  • Microservices: Every functional element is ultimately a software unit that can be replaced and upgraded independently.

3. Environment

  • jdk13(1.7+)
  • maven3.6.3(3.x)
  • IDEA2019.3.3
  • SpringBoot1.5.9.RELEASE

4. Configuration

1. MAVEN settings

Add the following configuration to the <profiles> tag in the maven->conf->settings.xml configuration file:

  <profiles>
  <profile>    
		  <id>jdk-13</id>    
			 <activation>    
				  <activeByDefault>true</activeByDefault>    
				  <jdk>13</jdk>    
			  </activation>    
		   <properties>    
				<maven.compiler.source>13</maven.compiler.source>    
				<maven.compiler.target>13</maven.compiler.target>    
				<maven.compiler.compilerVersion>13</maven.compiler.compilerVersion>    
			</properties>    
	   </profile> 
  </profiles>
2. IDEA settings (set according to the version)

insert image description here
insert image description here

5、Spring Boot HelloWorld

Function: The browser sends a hello request, the server accepts and processes the request, and responds with the HelloWorld string.

1. Create a maven project; (jar) (can also be automatically built on the official website)

insert image description here
insert image description here
insert image description here
insert image description here

2. Import SpringBoot dependencies (you can add the following dependencies or automatically build and download projects on the official website)
  • <parent> parent project
  • spring-boot-starter: spring-boot scene starter, importing the components that the web module normally depends on Yu Ning
 <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
 </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
3. Write the main program

insert image description here

4. Write the controller

insert image description here

5. Start SpringBoot (start in main)

insert image description here

6. The browser enters the URL (http://localhost:8080/hello) to complete

insert image description here

6. Simplify deployment

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

insert image description here
insert image description here
Enter the jar package from the command line, and use the command: java -jar (file name) to run it.

Guess you like

Origin blog.csdn.net/qq_46043634/article/details/108035094