Spring Boot不支持@WebServlet

编程入门 行业动态 更新时间:2024-10-22 13:35:06
本文介绍了Spring Boot不支持@WebServlet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我创建了一个Servlet(从HttpServlet扩展),并按照3.0规范进行了注释

I created a Servlet (extending from HttpServlet) and annotated as per 3.0 specs with

@WebServlet(name="DelegateServiceExporter", urlPatterns={"/remoting/DelegateService"})

Spring Boot中的@Configuration类扫描此servlet的包.但是,当我的Spring Boot应用程序启动时,它没有记录它已将该servlet部署在嵌入式Tomcat 8.0.15容器中.

My @Configuration class in Spring Boot scans this servlet's package. However, it does not log that it has deployed this servlet in the embedded Tomcat 8.0.15 container when my Spring Boot application starts up.

因此,我也将@Component添加到了我的servlet.现在,Spring Boot注册了servlet(向我证明了扫描软件包的设置正确),但是随后它使用驼峰式大小写的基于类名称的URL模式注册了该servlet.所以,这样更好-例如,我注册了一个servlet,但是URL映射错误!

So, I added @Component to my servlet as well. Now, Spring Boot registers the servlet (proving to me that the scan package was correctly set up), but then it registers it with a URL pattern based on a class name using camel case. So, that was better - e.g., I got a servlet registered, but with the wrong URL mappings!

2015-01-05 11:29:08,516 INFO (localhost-startStop-1) [org.springframework.boot.context.embedded.ServletRegistrationBean] Mapping servlet: 'delegateServiceExporterServlet' to [/delegateServiceExporterServlet/]

如何让Spring Boot自动加载所有带有@WebServlet注释的servlet并遵守其url映射?

How do I get Spring Boot to auto-load all @WebServlet annotated servlets and honor their url mappings?

推荐答案

在引导类中添加@ServletComponentScan.

例如

@SpringBootApplication @ServletComponentScan public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }

这将使Spring Boot能够扫描@WebServlet和@WebListener.

This will enable spring boot to scan @WebServlet as well as @WebListener.

更多推荐

Spring Boot不支持@WebServlet

本文发布于:2023-10-29 10:02:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539406.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不支持   Spring   Boot   WebServlet

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!