English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
SpringBoot Starter Web ha due funzionalità importanti:
Compatibile con lo sviluppo web Configurazione automatica
Per sviluppare un'applicazione web, è necessario aggiungere le seguenti dipendenze nel file pom.xml:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.2.2.RELEASE</version> </dependency>
Il programma di avvio di Spring web utilizza Spring MVC, REST e Tomcat come server embedded di default. Una singola dipendenza spring-boot-starter-web può ottenere tutte le dipendenze correlate allo sviluppo web in modo trasparente. Inoltre, riduce il conteggio delle dipendenze da costruire. spring-boot-starter-web dipende trasparentemente dai seguenti elementi:
org.springframework.boot: spring-boot-starter org.springframework.boot: spring-boot-starter-tomcat org.springframework.boot: spring-boot-starter-validation com.fasterxml.jackson.core: jackson-databind org.springframework: spring-web org.springframework: spring-webmvc
Per impostazione predefinita, spring-boot-starter-web include le seguenti dipendenze del server Tomcat:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <version>2.0.0.RELEASE</version> <scope>compile</scope> </dependency>
spring-boot-starter-web automaticamente configura i seguenti per lo sviluppo web:
servlet scheduler pagine di errore Web JAR per la gestione delle dipendenze statiche container servlet embedded
Ogni applicazione Spring Boot include un server embedded. Il server embedded viene integrato come parte dell'applicazione deployabile. I vantaggi del server embedded sono che non dobbiamo preinstallare il server nell'ambiente. Utilizzando Spring Boot, il server embedded predefinito è Tomcat 。 Spring Boot supporta anche altri due server embedded:
server Jetty server Undertow
per pila servletapplicazione, spring-boot-starter-web attraverso l'inclusione spring-boot-starter-tomcat per includere Tomcat ,ma possiamo utilizzare spring-boot-starter-jetty o spring -boot-starter-undertow 。
per reactoreapplicazione, spring-boot-starter-webflux inclusi inclusi spring-boot-starter-reactor-netty per implementare Reactor Netty ,ma possiamo utilizzare spring-boot-starter-tomcat,spring-boot-starter-jetty,
Spring Boot supporta anche quello chiamato server Jetty. È un server HTTP e un contenitore Servlet che ha la funzione di fornire contenuti statici e dinamici.
Se si desidera aggiungere un server Jetty all'applicazione, è necessario aggiungere spring-boot-starter-jetty dipendenze.
Ricorda: . Assicurati di usare il server Jetty nell'applicazione, elimina esclude il server Tomcat predefinito spring-boot-starter-web . Evita conflitti tra i server.
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jetty</artifactId> </dependency>
Possiamo anche usare application.properties Il file definisce il comportamento del server Jetty personalizzato.
Spring Boot offre anche un altro chiamato Undertow Il server è anche un server web embeddabile come Jetty. È scritto in Java, gestito e sponsorizzato da JBoss. I principali vantaggi del server Undertow sono:
supporto HTTP/2 supporto HTTP upgrade supporto Websocket fornisce supporto per Servlet 4.0 flessibile embeddabile
Ricorda: : Assicurati di usare il server Undertow nell'applicazione, elimina in spring-boot-starteresclude il server Tomcat predefinito -web.evita conflitti tra i server.
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-undertow</artifactId> </dependency>
Possiamo anche usare application.properties Il file definisce il comportamento del server Undertow personalizzato.
spring-boot-starter-web contiene le dipendenze web di spring, tra cui spring-boot-starter-tomcat. spring-boot-starter-web contiene il seguente contenuto:
spring-boot-starter jackson spring-core spring-mvc spring-boot-starter-tomcat
spring-boot-starter-tomcat contiene tutto il contenuto relativo al server Tomcat.
core el logging websocket
starter-tomcat ha le seguenti dipendenze:
<dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-core</artifactId> <version>8.5.23</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-el</artifactId> <version>8.5.23</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-websocket</artifactId> <version>8.5.23</version> <scope>compile</scope> </dependency>
Possiamo anche utilizzare spring-mvc Senza utilizzare il server Tomcat incorporato. Se si desidera farlo, è necessario utilizzare
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency>