@ServletComponentScan
通常标注在启动类上,用于设置servlet容器组建的扫描,被设定的范围内 Servlet、Filter、Listener可以直接通过@WebServlet、@WebFilter、@WebListener注解自动注册,无需其他代码
1 2 3 4 5 6 7 8 9 10 11 12 13
| @Target({ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented @Import({ServletComponentScanRegistrar.class}) public @interface ServletComponentScan { @AliasFor("basePackages") String[] value() default {};
@AliasFor("value") String[] basePackages() default {};
Class<?>[] basePackageClasses() default {}; }
|
- value与basePackages互设置别名
- basePackageClasses:可以通过其来设置需扫描的包类路径
1 2 3 4 5 6 7 8
| @SpringBootApplication @ServletComponentScan("com.test") public class Application {
public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
|
1 2 3 4 5 6 7 8 9 10 11 12 13
| package com.test
@WebServlet(name="TestServlet",urlPatterns="/test") public class TestServlet extends HttpServlet { private static final long serialVersionUID = 1L;
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println("test"); } }
|
参考资料:
[1]https://blog.csdn.net/m0_37739193/article/details/85097477
版权声明:本文为博主原创文章,欢迎转载,转载请注明作者、原文超链接,感谢各位看官!!!
本文出自:monkeyGeek
座右铭:生于忧患,死于安乐
欢迎志同道合的朋友一起交流、探讨!
monkeyGeek