Annuaire d'articles
1. Implémentation du code
1.1 Créer un projet Maven
Créer un projet Maven en utilisant l'idée:
entrez GroupId et ArtifactId:
étape suivante
1.2 Ajouter la dépendance de démarrage de SpringBoot
Ajouter une dépendance de démarrage dans pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.RELEASE</version>
</parent>
Ajouter une dépendance springMVC
1.3 Ajouter une classe de démarrage 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 Contrôleur d'écriture
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
Démarrez la classe de test, consultez le journal de démarrage
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: 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
Entrée: http: // localhost: 8080 /
affichage de démonstration
2. Analyse de démarrage rapide
- @SpringBootApplication: annoter la classe de démarrage de SpringBoot, l'annotation a plusieurs fonctions (analyse détaillée plus loin)
- SpringApplication.run (MySpringBootApplication.class) représente la classe de démarrage qui exécute SpringBoot et le paramètre est
l'objet bytecode de la classe de démarrage SpringBoot
3. Déploiement à chaud
Une fois le code modifié, il prend effet sans redémarrage, ce qui est appelé déploiement à chaud. Ajouter dans pom.xml
<!--热部署配置-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
Faites attention au réglage de la fonction de compilation automatique d'idées.
Ensuite, Maj + Ctrl + Alt + /, sélectionnez Registre