springboot项目的启动探秘


本文持续更新中。

springboot版本 2.1.0

让我们带着以下问题:

  • 一个springboot项目的banner是什么时候打印的?
  • 数据库连接池这些对数据库进行设置的操作在哪里进行的?
  • 一个项目启动后是怎样接收接口访问的?

开始我们的探秘之路?

一、探秘之路

  1. 首先,从springboot 的main方法着手
@SpringBootApplication
@ImportResource({
   "classpath:applicationContext-all.xml"})
@EnableAspectJAutoProxy (exposeProxy = true)
@EnableTransactionManagement
@Component
@EnableOAuthServer
public class Application 
{
   
    public static void main( String[] args )
    {
   
    	if(args != null && args.length>0) {
   
    		for(String arg:args) {
   
    			if(arg.startsWith("setuFilePath:")) {
   
    				String setuFilePath = arg.substring(13);
    				SetuSystemUtil.setuFilePath = setuFilePath;
    				System.out.println("使用外部配置文件:"+setuFilePath);
    			}
    		}
    	}
    	
    	
    	SetuSystemUtil.applicationName="founder_gateway";
    	SetuSystemUtil.sessionBeanClazz=SetuSession.class;
        SpringApplication.run(Application.class, args);
    }

}

为了指定默认启动类和默认设置,我们调用SpringApplication.run(Application.class, args)启动项目。

  1. ?,现在,进入org.springframework.boot.SpringApplication#run(java.lang.Class<?>, java.lang.String…)方法。
/**
	 * Static helper that can be used to run a {@link SpringApplication} from the
	 * specified source using default settings.
	 * @param primarySource the primary source to load
	 * @param args the application arguments (usually passed from a Java main method)
	 * @return the running {@link ApplicationContext}
	 */
	public static ConfigurableApplicationContext run(Class<?> primarySource,
			String... args) {
   
		return run(new Class<?>[] {
    primarySource }, args);
	}

该方法可以运行一个SpringApplication。run方法接收的第一个参数是一个Class<?>类型的数组。

  1. 继续。进入org.springframework.boot.SpringApplication#run(java.lang.Class<?>[], java.lang.String[])
/**
	 * Static helper that can be used to run a {@link SpringApplication} from the
	 * specified sources using default settings and user supplied arguments.
	 * @param primarySources the primary sources to load
	 * @param args the application arguments (usually passed from a Java main method)
	 * @return the running {@link ApplicationContext}
	 */
	public static ConfigurableApplicationContext run(Class<?>[] primarySources,
			String[] args) {
   
		return new SpringApplication(primarySources).run(args);
	}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值