springapplication注解_java导入外部jar包

springapplication注解_java导入外部jar包SpringApplication定义:Spring应用引导类,提供便利的自定义行为方法场景:嵌入式Web应用和非Web应用准备阶段配置:SpringBean来源 Java配置Class:Spring注解驱动中Java配置类,大多是情况下是Spring模式注解锁标注的类,如被@configuration标注的类 XML上下文配置文件:用于Spring传统配置驱动中的xml文件 BeanDefinitionLoader(BeanDefinitionRegistryregistr

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

SpringApplication

定义:Spring应用引导类,提供便利的自定义行为方法
场景:嵌入式Web应用和非Web应用

准备阶段

  • 配置:Spring Bean来源
    • Java配置Class:Spring注解驱动中Java配置类,大多是情况下是Spring 模式注解锁标注的类,如被@configuration标注的类
    • XML上下文配置文件:用于Spring 传统配置驱动中的xml文件
BeanDefinitionLoader(BeanDefinitionRegistry registry, Object... sources) {
        Assert.notNull(registry, "Registry must not be null");
        Assert.notEmpty(sources, "Sources must not be empty");
        this.sources = sources;
        // 使用AnnotatedBeanDefinitionReader进行配置
        this.annotatedReader = new AnnotatedBeanDefinitionReader(registry);
        // 使用XmlBeanDefinitionReader进行配置
        this.xmlReader = XML_ENABLED ? new XmlBeanDefinitionReader(registry) : null;
        this.groovyReader = this.isGroovyPresent() ? new GroovyBeanDefinitionReader(registry) : null;
        this.scanner = new ClassPathBeanDefinitionScanner(registry);
        this.scanner.addExcludeFilter(new BeanDefinitionLoader.ClassExcludeFilter(sources));
    }
  • 推断:Web应用类型 和 主引导类(Main Class)
    • Web Reactive:webApplicaitonType.REACTIVE
    • Web Servlet:webApplicaitonType.SERVLET
static WebApplicationType deduceFromClasspath() {
        // WEBFLUX_INDICATOR_CLASS = "org.springframework.web.reactive.DispatcherHandler";
        // WEBMVC_INDICATOR_CLASS = "org.springframework.web.servlet.DispatcherServlet";
        // JERSEY_INDICATOR_CLASS = "org.glassfish.jersey.servlet.ServletContainer";
        // 如果没有上面的方式,默认使用Servlet_indicator_classes,如果共存的情况下优先使用Servlet_indicator_classes
		if (ClassUtils.isPresent(WEBFLUX_INDICATOR_CLASS, null) && !ClassUtils.isPresent(WEBMVC_INDICATOR_CLASS, null)
				&& !ClassUtils.isPresent(JERSEY_INDICATOR_CLASS, null)) {
			return WebApplicationType.REACTIVE;
		}
		for (String className : SERVLET_INDICATOR_CLASSES) {
			if (!ClassUtils.isPresent(className, null)) {
				return WebApplicationType.NONE;
			}
		}
		return WebApplicationType.SERVLET;
	}

 可以在引导类中指定引导的具体类型

/**
 * {@link SpringApplication} 引导类
 */

public class SpringApplicationBootstrap {
    public static void main(String[] args) {
        // 交给其运行的类只要上面有@SpringBootApplicat ion注解就行,不一定是主类名
        // SpringApplication.run(ApplicationConfiguration.class, args);
        HashSet<String> set = new HashSet<>();
        set.add(ApplicationConfiguration.class.getName());
        SpringApplication springApplication = new SpringApplication();
        springApplication.setSources(set);
        // 默认为Servlet类型,此处对它进行强制关闭,变成普通类型--主线程会中断[非web容器], web容器主线程会阻塞等待请求
        springApplication.setWebApplicationType(WebApplicationType.NONE);
        ConfigurableApplicationContext context = springApplication.run(args);
        // 反射EnhancerBySpringCGLIB
        // com.SpringBoot.study.SpringApplicationBootstrap$ApplicationConfiguration$$EnhancerBySpringCGLIB$$ea8d68dc@400d912a
        System.out.println(context.getBean(ApplicationConfiguration.class));
    }
    
    @SpringBootApplication
    public static class ApplicationConfiguration{
    }
}

springapplication注解_java导入外部jar包

  • 加载:应用上下文初始化器 和 应用事件监听器
    public SpringApplication(ResourceLoader resourceLoader, Class<?>... primarySources) {
    		this.resourceLoader = resourceLoader;
    		Assert.notNull(primarySources, "PrimarySources must not be null");
    		this.primarySources = new LinkedHashSet<>(Arrays.asList(primarySources));
    		this.webApplicationType = WebApplicationType.deduceFromClasspath();
    		this.bootstrappers = new ArrayList<>(getSpringFactoriesInstances(Bootstrapper.class));
            // 上下文初始化器
    		setInitializers((Collection) getSpringFactoriesInstances(ApplicationContextInitializer.class));
            // 监听器
    		setListeners((Collection) getSpringFactoriesInstances(ApplicationListener.class));
    		this.mainApplicationClass = deduceMainApplicationClass();
    	}
    • 上下文初始化器技术
      • 实现类:org.springframework.core.io.support.SpringFactoriesLoader
      • 配置资源:META-INF/spring.factories
      • 排序:AnnotationAwareOrder

《慕课网–深入Spring Boot2.0》

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/195421.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 损失函数loss大总结

    损失函数loss大总结分类任务loss:二分类交叉熵损失sigmoid_cross_entropy:TensorFlow接口:tf.losses.sigmoid_cross_entropy(multi_class_labels,logits,weights=1.0,label_smoothing=0,scope=None,loss_c…

    2022年6月19日
    15
  • 组合数常用计算公式

    组合数常用计算公式Cnm=n!m!∗(n−m)!C_n^m=\frac{n!}{m!*(n-m)!}Cnm​=m!∗(n−m)!n!​Cn2=n∗(n−1)2C_n^2=\frac{n*(n-1)}{2}Cn2​=2n∗(n−1)​Cn3=n∗(n−1)∗(n−2)6C_n^3=\frac{n*(n-1)*(n-2)}{6}Cn3​=6n∗(n−1)∗(n−2)​Cnm=Cn−1m−1+Cn−1mC_n^m…

    2022年7月25日
    7
  • windows上安装redis并安装php5.6的redis扩展

    windows上安装redis并安装php5.6的redis扩展

    2021年10月16日
    56
  • iOS跑步软件开发-从无到有

    iOS跑步软件开发-从无到有前言经过两个多月的开发与调试,全民星跑1.0.1终于上线了,首先要感谢曲总和洛洛爱吃肉的技术支持.全民星跑作为一个以跑步计步为主要功能的软件,骚栋在开发过程中实在是遇到了不少的坑,这篇博客会分为加速仪计步和跑步计步两个模块来说明,不过有一点我想先声明,因为人力资源有限,所以可能在计步的逻辑上跟不上咕咚或者是Keep这些大厂,望各位看官见谅.????????????功能规划一个App如何统计一个人的运动?这里主要有两种方式,一种是使用陀螺仪(或是加速仪)获取手机各个方向的加速度来统计用户的

    2022年7月26日
    2
  • 今天刚刚申请的这个账号。。「建议收藏」

    今天刚刚申请的这个账号。。「建议收藏」珍藏吧论坛:http://zcb.5d6d.com/欢迎大家交流。

    2022年5月27日
    28
  • JMESPath_java中jframe怎么用

    JMESPath_java中jframe怎么用前言JMESPath是JSON的查询语言。您可以从JSON文档中提取和转换元素官方文档:https://jmespath.org/tutorial.html基本表达式JMESPath用的最多的

    2022年7月30日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号