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)
上一篇 2025年10月17日 下午4:43
下一篇 2025年10月17日 下午5:15


相关推荐

  • pycharm 2021.11.3激活(注册激活)

    (pycharm 2021.11.3激活)最近有小伙伴私信我,问我这边有没有免费的intellijIdea的激活码,然后我将全栈君台教程分享给他了。激活成功之后他一直表示感谢,哈哈~IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html…

    2022年3月28日
    71
  • Kimi PPT助手

    Kimi PPT助手

    2026年3月12日
    1
  • 爬虫为啥需要大量的ip_简述网络爬虫的工作原理

    爬虫为啥需要大量的ip_简述网络爬虫的工作原理http/https等爬虫代理ip的基本实现原理爬虫工作者在试用爬虫进行数据搜集的过程中经常会遇到这样的情况,刚开始的时候爬虫的运行情况是正常的,数据的抓取状况也在有条不紊的进行着,然而可能你一眼照顾不到就会出现错误,比如403Forbidden,这时候你打开网页的话,网页上面会提示你,“您的IP访问频率太高”这样的字眼。出现这种现象的原因就是被访问网站采取了反爬虫机制,比如,服务器会检测某个IP在单位时间内的请求次数,如果超过了这个阈值,就会直接拒绝服务,返回一些错误信息,这种情况可以称为封IP。那

    2022年10月8日
    4
  • 【matlab】函数meshgrid的用法详解(生成网格矩阵)和ndgrid的区别及用法「建议收藏」

    【matlab】函数meshgrid的用法详解(生成网格矩阵)和ndgrid的区别及用法「建议收藏」meshgrid函数用来生成网格矩阵,可以是二维网格矩阵,也可以是三维。对于生成二维网格,用法为:[xy]=meshgrid(ab); %a和b是一维数组,如a=[123];b=[234];则生成的x和y都是二维的矩阵,x的每行都是123,共三行,y每列都是234,共三列。举个实例:Forexample, toevaluateth

    2022年6月12日
    49
  • 2025年豆包大模型Seedream 2.0技术报告:原生中英双语图像生

    2025年豆包大模型Seedream 2.0技术报告:原生中英双语图像生

    2026年3月12日
    2
  • 常用数据库查询语句

    常用数据库查询语句常用数据库查询语句基本查询 select 字段 1 字段 2 from 表名 例如 selectid namefromstu 条件查询 select 字段 1 字段 2 from 表名 where 字段关系符号值 关系符号 lt gt lt 大于等于大于等于小于等于不等于例如 select fromstuid gt 2 andorin 范围内满足 in 内部条件

    2026年3月19日
    1

发表回复

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

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