Springboot之---强大的Servlet(五)

简介: 如今回头看下Servlet不仅如此强大,还具有很强烈的参考意义,能在现如今流行的大部分框架中找到它的影子。下面文章不止与探索Servlet,可能在其中穿插其他的关联知识点,旨在能从此次的学习中获取更多的知识点参考资料总结,转化为自己的理解输出,在文中我尽量以截图+复制全限定类名的方式记录,以便感兴趣的再次查找。

Servlet on Springboot

组件扫描:ServletComponentScan

熟悉波~ 是不是应用跟Springboot的@ComponentScan如出一辙

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Import(ServletComponentScanRegistrar.class)
public @interface ServletComponentScan {

    /**
     * Alias for the {@link #basePackages()} attribute. Allows for more concise annotation
     * declarations e.g.: {@code @ServletComponentScan("org.my.pkg")} instead of
     * {@code @ServletComponentScan(basePackages="org.my.pkg")}.
     * @return the base packages to scan
     */
    @AliasFor("basePackages")
    String[] value() default {};

    /**
     * Base packages to scan for annotated servlet components. {@link #value()} is an
     * alias for (and mutually exclusive with) this attribute.
     * <p>
     * Use {@link #basePackageClasses()} for a type-safe alternative to String-based
     * package names.
     * @return the base packages to scan
     */
    @AliasFor("value")
    String[] basePackages() default {};

    /**
     * Type-safe alternative to {@link #basePackages()} for specifying the packages to
     * scan for annotated servlet components. The package of each class specified will be
     * scanned.
     * @return classes from the base packages to scan
     */
    Class<?>[] basePackageClasses() default {};

}

配置声明:@interface 暴露SpringBean @Bean
事件:Event

filter:

webFilter
OncePerRequestFilter:只调用一次且是线程安全的
而其子类得ApplicationContextHeaderFilter调用的dofilter方法就是我们上面提到的真正在请求中执行的filter

激活Springbootweb

流程

文无第一,武无第二,没有最好的技术框架或体系,只有最适合当下业务的框架或体系
谈谈你对技术的理解:天上飞的理念,必定有落地的实现

组装SpringApplicationBuilder

你看看这名字就知道他以后干啥的,并且它包含了太多太多的东西,
SpringApplication和ApplicationContext实例的生成器,基本包含了所有的SpringbootApplacation特性

    private final SpringApplication application;

    private ConfigurableApplicationContext context;

    private SpringApplicationBuilder parent;
    AtomicBoolean是不是的看看
    private final AtomicBoolean running = new AtomicBoolean(false);

    private final Set<Class<?>> sources = new LinkedHashSet<>();

    private final Map<String, Object> defaultProperties = new LinkedHashMap<>();

    private ConfigurableEnvironment environment;

    private Set<String> additionalProfiles = new LinkedHashSet<>();

    private boolean registerShutdownHookApplied;

    private boolean configuredAsChild = false;
@SpringBootApplication
public class TestProfiles {
 
    public static void main(String[] args) {
        ConfigurableApplicationContext context = new SpringApplicationBuilder(TestProfiles.class)
                .properties("spring.config.location=classpath:/test-profiles.yml")
                .properties("spring.profiles.active=oracle")
                .run(args);
        // 输出变量
        System.out.println(context.getEnvironment().getProperty("jdbc.driver"));
 
        // 启动第二个Spring容器,指定端口为8848
        ConfigurableApplicationContext context2 = new SpringApplicationBuilder(TestProfiles.class)
                .properties("spring.config.location=classpath:/test-profiles.yml")
                .properties("spring.profiles.active=mysql")
                .properties("server.port=8848")
                .run(args);
        // 输出变量
        System.out.println(context2.getEnvironment().getProperty("jdbc.driver"));
    }
}

Springboot自动装配
/META-INF/spring.factories
XXXAotuConfigration
NIO不是异步IO而是非阻塞IO
java9推崇模块化

ClassLoader

public static void main(String[] args) {
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    while (true) {

        System.out.println(contextClassLoader.getClass().getName());
        ClassLoader parent = contextClassLoader.getParent();
        if (parent == null) {
            break;
        }

    }

    ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
    System.out.println(systemClassLoader.getClass().getName());
}

update_time =2022年2月14日13:48:19

传统的Servlet容器 Apache Tomcat

这里只记录了部分重要场景
包含核心组件
静态资源处理
类加载
连接器
JDBC数据源

HttpServletResponse

javax.servlet.http.HttpServletResponse

public static void main(String[] args) {
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    while (true) {

        System.out.println(contextClassLoader.getClass().getName());
        ClassLoader parent = contextClassLoader.getParent();
        if (parent == null) {
            break;
        }

    }

    ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
    System.out.println(systemClassLoader.getClass().getName());
}

除了其中的状态码之外,结合最近的测试其中的实现可具体参考
addHeader方法,getHeader方法等等
BootStrap--system---common---webapp

目录
相关文章
|
7月前
|
Java 应用服务中间件 容器
25 SpringBoot使用外置的Servlet容器
25 SpringBoot使用外置的Servlet容器
25 0
|
1天前
|
前端开发 Java 容器
SpringBoot中注册Servlet、Filter和Listener(代码和注解两种方式)
SpringBoot中注册Servlet、Filter和Listener(代码和注解两种方式)
65 0
|
7月前
|
前端开发 Java 应用服务中间件
24 SpringBoot配置嵌入式Servlet容器
24 SpringBoot配置嵌入式Servlet容器
40 0
24 SpringBoot配置嵌入式Servlet容器
|
Java API Spring
在spring boot中添加servlet filter *Listener
在spring boot中添加servlet filter *Listener
在spring boot中添加servlet filter *Listener
|
消息中间件 负载均衡 Java
Springboot之---强大的Servlet(十 一)
如今回头看下Servlet不仅如此强大,还具有很强烈的参考意义,能在现如今流行的大部分框架中找到它的影子。下面文章不止与探索Servlet,可能在其中穿插其他的关联知识点,旨在能从此次的学习中获取更多的知识点参考资料总结,转化为自己的理解输出,在文中我尽量以截图+复制全限定类名的方式记录,以便感兴趣的再次查找。
90 0
|
消息中间件 SQL 缓存
Springboot之---强大的Servlet(十)
如今回头看下Servlet不仅如此强大,还具有很强烈的参考意义,能在现如今流行的大部分框架中找到它的影子。下面文章不止与探索Servlet,可能在其中穿插其他的关联知识点,旨在能从此次的学习中获取更多的知识点参考资料总结,转化为自己的理解输出,在文中我尽量以截图+复制全限定类名的方式记录,以便感兴趣的再次查找。
119 0
|
存储 缓存 NoSQL
Springboot之---强大的Servlet(九)
如今回头看下Servlet不仅如此强大,还具有很强烈的参考意义,能在现如今流行的大部分框架中找到它的影子。下面文章不止与探索Servlet,可能在其中穿插其他的关联知识点,旨在能从此次的学习中获取更多的知识点参考资料总结,转化为自己的理解输出,在文中我尽量以截图+复制全限定类名的方式记录,以便感兴趣的再次查找。
59 0
|
SQL 缓存 安全
Springboot之---强大的Servlet(八)
如今回头看下Servlet不仅如此强大,还具有很强烈的参考意义,能在现如今流行的大部分框架中找到它的影子。下面文章不止与探索Servlet,可能在其中穿插其他的关联知识点,旨在能从此次的学习中获取更多的知识点参考资料总结,转化为自己的理解输出,在文中我尽量以截图+复制全限定类名的方式记录,以便感兴趣的再次查找。
59 0
|
设计模式 SQL 存储
Springboot之---强大的Servlet(七)
如今回头看下Servlet不仅如此强大,还具有很强烈的参考意义,能在现如今流行的大部分框架中找到它的影子。下面文章不止与探索Servlet,可能在其中穿插其他的关联知识点,旨在能从此次的学习中获取更多的知识点参考资料总结,转化为自己的理解输出,在文中我尽量以截图+复制全限定类名的方式记录,以便感兴趣的再次查找。
60 0
|
JSON 网络协议 前端开发
Springboot之---强大的Servlet(六)
如今回头看下Servlet不仅如此强大,还具有很强烈的参考意义,能在现如今流行的大部分框架中找到它的影子。下面文章不止与探索Servlet,可能在其中穿插其他的关联知识点,旨在能从此次的学习中获取更多的知识点参考资料总结,转化为自己的理解输出,在文中我尽量以截图+复制全限定类名的方式记录,以便感兴趣的再次查找
95 0