java - Spring Boot:spring-starter-web 的用途
问题描述
我是Spring
生态系统的新手,很多事情都很混乱。我有一个包含以下入门包的网络项目:spring-boot-starter-jersey
和spring-boot-starter-jetty
. 这将启动带有 Jersey servlet 的 Jetty 服务器。哪个好。但它不提供静态内容。所以,我安装了spring-boot-starter-web
它,它为resources/static
. 但我不明白怎么做。安装一个软件包只是为了提供静态内容似乎有点过头了。如果它是一个非 Spring 项目,我会使用 Jetty 创建一个新的 servlet 并链接一个base resource path
. 但我不确定如何在不使用spring-starter-web
.
那么,spring-starter-web
在我的项目设置中是否有任何附加价值(不包括静态资源服务)?
如何在Jetty
没有 ? 的情况下仅使用服务器静态资源starter-web
?
解决方案
这个 Spring Boot Starter Web 使用 Spring MVC、REST 和 Tomcat 作为默认的嵌入式服务器,因此您需要对其进行调整以将其替换为 Jetty。您可以通过以下方式做到这一点:
<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>
spring-boot-starter-web
传递性取决于以下内容:
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
此外,spring-boot-starter-web
自动配置 Web 开发通常需要的以下功能:
- 调度程序 Servlet
- 错误页面
- 用于管理静态依赖项的 Web JAR
- 嵌入式 servlet 容器
说了这么多,除非您真的想对项目的依赖项进行更细粒度的控制,否则我建议您使用spring-boot-starter-web
它,因为它可以节省大量样板代码。
推荐阅读
- python - 我面临 ModuleNotFoundError: No module named 'testCases' while running a code in google collab what to do
- parameters - 在 AnyLogic 中指定特定 GIS 点或长/纬度坐标的参数
- python - 如何获取所有周的列表
- r - R 中 plot() 函数的大小参数
- redis - M1 MacBookpro 安装 brew
- javascript - 如何在 A-Frame 中为特定实体隐藏默认手形光标或如何应用 css 光标属性“不允许”
- arrays - 在循环中转换我的程序,但它在数组中
- java - 如何通过“Mod Coder Pack”(MCP)在 Minecraft 中正确使用 Singleton?
- redis - 如果在 HA 场景中不需要持久性,则将 Redis 作为部署或 statefulset
- python - 如果组中存在特定值,则 pandas groupby 数据框列并创建新列