Directorio de artículos
1. Implementación del código
1.1 Crear proyecto Maven
Cree un proyecto Maven usando la idea:
Ingrese GroupId y ArtifactId:
Siguiente paso
1.2 Agregar la dependencia inicial de SpringBoot
Agregar dependencia de inicio en pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.RELEASE</version>
</parent>
Agregar dependencia springMVC
1.3 Agregar clase de arranque Springboot
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 Controlador de escritura
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 Prueba
Inicie la clase de prueba, vea el registro de inicio
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: 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
Entrada: http: // localhost: 8080 / demo
display
2. Análisis de inicio rápido
- @SpringBootApplication: anote la clase de inicio de SpringBoot, la anotación tiene múltiples funciones (análisis detallado más adelante)
- SpringApplication.run (MySpringBootApplication.class) representa la clase de inicio que ejecuta SpringBoot, y el parámetro es
el objeto bytecode de la clase de inicio SpringBoot
3. Despliegue en caliente
Después de modificar el código, surte efecto sin reiniciar, lo que se denomina implementación en caliente. Agregar en pom.xml
<!--热部署配置-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
Presta atención a configurar la función de compilación automática de ideas.
Luego Shift + Ctrl + Alt + /, seleccione Registro