springboot中怎么利用Tomcat容器实现自启动

  介绍

本篇文章给大家分享的是有关springboot中怎么利用Tomcat容器实现自启动,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。

一、春天通过注解导入豆大体可分为四种方式,我们主要来说以下进口的两种实现方法:

 springboot中怎么利用Tomcat容器实现自启动

1,通过实现ImportSerlector接口,实现豆加载:

public  class  TestServiceImpl  {   ,public  void  testImpl (), {   ,System.out.println(“我是通过importSelector导入进来的service");   ,}   }   public  class  TestService  implements  ImportSelector  {   ,@Override   ,public  String [], selectImports (AnnotationMetadata  annotationMetadata), {   ,return  new  String [] {“com.ycdhz.service.TestServiceImpl"};   ,}   }   @ configuration   @ import (value =, {TestService.class})   public  class  TestConfig  {   }   public  class  TestController  {   ,@ autowired   ,private  TestServiceImpl  testServiceImpl;   ,   ,@RequestMapping (“testImpl")   ,public  String  testTuling (), {   ,testServiceImpl.testImpl ();   ,return “Ok";   ,}   }

2,通过实现ImportSerlector接口,实现豆加载:

public  class  TestService  {   ,public  TestService (), {   ,System.out.println(“我是通过ImportBeanDefinitionRegistrar导入进来的组件“);   ,}   }   public  class  TestImportBeanDefinitionRegistrar  implements  ImportBeanDefinitionRegistrar  {   ,@Override   ,public  void  registerBeanDefinitions (AnnotationMetadata  importingClassMetadata, BeanDefinitionRegistry 注册表),{   ,//定义一个BeanDefinition   ,RootBeanDefinition  beanDefinition =, new  RootBeanDefinition (TestService.class);   ,//把自定义的bean定义导入到容器中   ,registry.registerBeanDefinition (“testService" beanDefinition);   ,}   }   @ configuration   @ import (TestImportBeanDefinitionRegistrar.class)   public  class  TestConfig  {   }

二,Springboot启动过程中会自动装配

我们从spring-boot-autoconfigure-2.0.6.RELEASE。jar下搜索到Tomcat的相关配置,发现有两个自动装配类,分别包含了三个定制器(面向对象的单一职责原则),还有一个工厂类。

 springboot中怎么利用Tomcat容器实现自启动

2.1, TomcatWebServerFactoryCustomizer:定制Servlet和无功服务器通用的Tomcat特定功能。

public  class  TomcatWebServerFactoryCustomizer 实现了   ,WebServerFactoryCustomizer Ordered  {   ,@Override   ,public  void 定制(ConfigurableTomcatWebServerFactory 工厂),{   ,ServerProperties  properties =, this.serverProperties;   ,ServerProperties.Tomcat  tomcatProperties =, properties.getTomcat ();   ,PropertyMapper  PropertyMapper =, PropertyMapper.get ();   ,propertyMapper.from (tomcatProperties:: getBasedir) .whenNonNull ()   ,,(工厂::setBaseDirectory);   ,propertyMapper.from (tomcatProperties:: getBackgroundProcessorDelay) .whenNonNull ()   ,。as(时间::getSeconds)。as(长::intValue)   ,,(工厂::setBackgroundProcessorDelay);   ,customizeRemoteIpValve(工厂);   ,propertyMapper.from (tomcatProperties:: getMaxThreads)当(::isPositive)   ,,((maxThreads),→, customizeMaxThreads(工厂,   tomcatProperties.getMaxThreads才能()));   ,propertyMapper.from (tomcatProperties:: getMinSpareThreads)当(::isPositive)   ,,((minSpareThreads),→, customizeMinThreads(工厂,,minSpareThreads));   ,propertyMapper.from ((),→, determineMaxHttpHeaderSize())当(::isPositive)   ,,((maxHttpHeaderSize),→, customizeMaxHttpHeaderSize(工厂,   maxHttpHeaderSize才能));   ,propertyMapper.from (tomcatProperties:: getMaxHttpPostSize)   ,当((maxHttpPostSize),→, maxHttpPostSize  !=, 0)   ,,((maxHttpPostSize),→, customizeMaxHttpPostSize(工厂,   maxHttpPostSize才能));   ,propertyMapper.from (tomcatProperties:: getAccesslog)   ,当(ServerProperties.Tomcat.Accesslog:: isEnabled)   ,,((启用),→,customizeAccessLog(工厂));   ,propertyMapper.from (tomcatProperties:: getUriEncoding) .whenNonNull ()   ,,(工厂::setUriEncoding);   ,propertyMapper.from(属性::getConnectionTimeout) .whenNonNull ()   ,,((connectionTimeout),→, customizeConnectionTimeout(工厂,   connectionTimeout才能));   ,propertyMapper.from (tomcatProperties:: getMaxConnections)当(::isPositive)   ,,((maxConnections),→, customizeMaxConnections(工厂,,maxConnections));   ,propertyMapper.from (tomcatProperties:: getAcceptCount)当(::isPositive)   ,,((acceptCount),→, customizeAcceptCount(工厂,,acceptCount));   ,customizeStaticResources(工厂);   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

springboot中怎么利用Tomcat容器实现自启动