Article Directory
1. Code implementation
1.1 Create Maven Project
Create Maven project using idea:
Enter GroupId and ArtifactId:
Next step
1.2 Add SpringBoot's starting dependency
Add start dependency in pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.RELEASE</version>
</parent>
Add springMVC dependency
1.3 Add Springboot boot class
package com.freedom;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MySpringBootApplication {
public static void main(String[] args) {
SpringApplication.run(MySpringBootApplication.class);
}
}
1.4 Write Controller
package com.freedom.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class DemoController {
@RequestMapping("/demo")
@ResponseBody
public String quick() {
return "springboot-demo 访问成功!";
}
}
1.5 Test
Start the test class, view the startup log
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.0.RELEASE)
2019-11-07 21:53:21.790 INFO 16736 --- [ main] com.freedom.MySpringBootApplication : Starting MySpringBootApplication on To-be-better with PID 16736 (E:\11_ideaworkspace\springboot-demo\target\classes started by wiljz in E:\11_ideaworkspace\springboot-demo)
2019-11-07 21:53:21.795 INFO 16736 --- [ main] com.freedom.MySpringBootApplication : No active profile set, falling back to default profiles: default
2019-11-07 21:53:26.499 INFO 16736 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-11-07 21:53:26.536 INFO 16736 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-11-07 21:53:26.536 INFO 16736 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.27]
2019-11-07 21:53:26.791 INFO 16736 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-11-07 21:53:26.791 INFO 16736 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 4695 ms
2019-11-07 21:53:27.100 INFO 16736 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-11-07 21:53:27.466 INFO 16736 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2019-11-07 21:53:27.469 INFO 16736 --- [ main] com.freedom.MySpringBootApplication : Started MySpringBootApplication in 7.905 seconds (JVM running for 9.323)
2019-11-07 21:53:45.936 INFO 16736 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2019-11-07 21:53:45.936 INFO 16736 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2019-11-07 21:53:45.941 INFO 16736 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 5 ms
Input: http: // localhost: 8080 / demo
display
2. Quick start analysis
- @SpringBootApplication: Annotate the startup class of SpringBoot, the annotation has multiple functions (detailed analysis later)
- SpringApplication.run (MySpringBootApplication.class) represents the startup class that runs SpringBoot, and the parameter is
the bytecode object of the SpringBoot startup class
3. Hot deployment
After the code is modified, it takes effect without restarting, which is called hot deployment. Add in pom.xml
<!--热部署配置-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
Pay attention to setting the idea automatic compilation function.
Then Shift + Ctrl + Alt + /, select Registry