我创建了一个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
发布评论