当前位置: 首页 > news >正文

石家庄哪里有做网站交换友情链接的渠道

石家庄哪里有做网站,交换友情链接的渠道,半导体网站建设,浅谈高校网站群的建设前言 首先确定springboot在spring基础上主要做了哪些改动&#xff1a;内嵌tomcatspi技术动态加载 一、基本实现 1. 建一个工程目录结构如下&#xff1a; springboot: 源码实现逻辑 user : 业务系统2.springboot工程项目构建 1. pom依赖如下 <dependencies>…

前言

 首先确定springboot在spring基础上主要做了哪些改动:
  1. 内嵌tomcat
  2. spi技术动态加载

一、基本实现

1. 建一个工程目录结构如下:

springboot:  源码实现逻辑
user         :   业务系统

在这里插入图片描述

2.springboot工程项目构建

1. pom依赖如下

   <dependencies><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.3.18</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-web</artifactId><version>5.3.18</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>5.3.18</version></dependency><dependency><groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><version>4.0.1</version></dependency><dependency><groupId>org.apache.tomcat.embed</groupId><artifactId>tomcat-embed-core</artifactId><version>9.0.60</version></dependency></dependencies>

2. SpringBoot时,核心会用到SpringBoot一个类和注解:

  1. @SpringBootApplication,这个注解是加在应用启动类上的,也就是main方法所在的类
  2. SpringApplication,这个类中有个run()方法,用来启动SpringBoot应用的.

下面一一实现:

 @Retention(RetentionPolicy.RUNTIME)@Target(ElementType.TYPE)@Configuration@ComponentScan@Import(KcImportSelect.class)
public @interface KcSpringBootApplication {}
public class KcSpringApplication {public static AnnotationConfigWebApplicationContext  run(Class cls){/*** spring启动步骤:* 1、构建上下文对象* 2、注册配置类* 3、刷新容器*/AnnotationConfigWebApplicationContext  context=new AnnotationConfigWebApplicationContext();context.register(cls);context.refresh();/*** 内嵌tomcat\jetty  启动*/WebServer  webServer=getWebServer(context);webServer.start();return context;}/*** 获取服务,有可能tomcat\jetty或者其他服务器* @param context* @return*/public static WebServer getWebServer(AnnotationConfigWebApplicationContext  context){Map<String, WebServer> beansOfType = context.getBeansOfType(WebServer.class);if(beansOfType.isEmpty()||beansOfType.size()>1){throw new NullPointerException();}return beansOfType.values().stream().findFirst().get();}}
3.内嵌tomcat、jetty服务器实现

项目根据pom配置动态实现tomcat\jetty内嵌要求如下:

  1. 如果项目中有Tomcat的依赖,那就启动Tomcat
  2. 如果项目中有Jetty的依赖就启动Jetty
  3. 如果两者都没有则报错
  4. 如果两者都有也报错

首先定义服务接口WebServer

public interface WebServer {void  start()  ;
}

tomcat服务实现:

public class TomcatWebServer implements WebServer {private Tomcat tomcat;public TomcatWebServer(WebApplicationContext webApplicationContext) {tomcat = new Tomcat();Server server = tomcat.getServer();Service service = server.findService("Tomcat");Connector connector = new Connector();connector.setPort(8081);Engine engine = new StandardEngine();engine.setDefaultHost("localhost");Host host = new StandardHost();host.setName("localhost");String contextPath = "";Context context = new StandardContext();context.setPath(contextPath);context.addLifecycleListener(new Tomcat.FixContextListener());host.addChild(context);engine.addChild(host);service.setContainer(engine);service.addConnector(connector);tomcat.addServlet(contextPath, "dispatcher", new DispatcherServlet(webApplicationContext));context.addServletMappingDecoded("/*", "dispatcher");}@Overridepublic void start() {try {System.out.println("tomcat start......");tomcat.start();}catch (Exception e){e.printStackTrace();}}
}

jetty服务实现(具体实现逻辑没写,具体实现逻辑类似tomcat实现)

public class JettyWebServer implements WebServer{@Overridepublic void start() {System.out.println("jetty  start......");}
}

思考:jetty\tomcat都已实现,总不能用if/else这样决定用哪个服务扩展性太差,基于此,就联想到spring的Condition条件注解和参考springboot中的OnClassCondition这个注解。

具体实现如下:

public class KcOnClassCondition implements Condition {@Overridepublic boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {Map<String, Object> annotationAttributes = metadata.getAnnotationAttributes(KcConditionalOnClass.class.getName());String value = (String) annotationAttributes.get("value");try {context.getClassLoader().loadClass(value);} catch (ClassNotFoundException e) {return false;}return true;}
}
@Configuration
public class WebServerConfiguration{@Bean@KcConditionalOnClass("org.apache.catalina.startup.Tomcat")public TomcatWebServer tomcatWebServer( WebApplicationContext webApplicationContext){return new TomcatWebServer(webApplicationContext);}@Bean@KcConditionalOnClass("org.eclipse.jetty.server.Server")public JettyWebServer  jettyWebServer(){return new JettyWebServer();}
}

至此,springboot简化版已实现完成,首先启动看看
在这里插入图片描述

4.基于JDK的SPI实现扫描AutoConfiguration接口

  • AutoConfiguration接口
public interface AutoConfiguration {
}
  • 实现DeferredImportSelector接口实现类(具体为什么实现Import这个接口,请看以前的文章,主要这个接口具有延迟功能)
public class KcImportSelect implements DeferredImportSelector {@Overridepublic String[] selectImports(AnnotationMetadata importingClassMetadata) {ServiceLoader<AutoConfiguration> load = ServiceLoader.load(AutoConfiguration.class);List<String> list = new ArrayList<>();for (AutoConfiguration autoConfiguration : load) {list.add(autoConfiguration.getClass().getName());}return list.toArray(new String[0]);}
}
  • 即KcSpringBootApplication注解导入该配置类
 @Retention(RetentionPolicy.RUNTIME)@Target(ElementType.TYPE)@Configuration@ComponentScan@Import(KcImportSelect.class)
public @interface KcSpringBootApplication {}
  • WebServerConfiguration实现AutoConfiguration接口
@Configuration
public class WebServerConfiguration implements AutoConfiguration{@Bean@KcConditionalOnClass("org.apache.catalina.startup.Tomcat")public TomcatWebServer tomcatWebServer( WebApplicationContext webApplicationContext){return new TomcatWebServer(webApplicationContext);}@Bean@KcConditionalOnClass("org.eclipse.jetty.server.Server")public JettyWebServer  jettyWebServer(){return new JettyWebServer();}
}
  • 在springboot项目下创建META-INFO/service 接口全路径命名的文件,文件内容接口实现类全路径
    在这里插入图片描述

至此,springboot简易版已全部实现。

二、应用业务系统引入自己构建的springboot

1、user项目的pom依赖(引入自己构建的springboot项目)

    <dependencies><dependency><groupId>com.kc</groupId><artifactId>springboot</artifactId><version>1.0-SNAPSHOT</version></dependency></dependencies>

2、启动类

@ComponentScan(basePackages = {"kc.*"})@KcSpringBootApplication
public class UserApplication {public static void main(String[] args) {AnnotationConfigWebApplicationContext run = KcSpringApplication.run(UserApplication.class);System.out.println(run.getBeanFactory());}
}

3、实现具体业务类

@RestController
public class UserController {@Autowiredprivate UserService userService;@GetMapping("test")public String test() {return userService.test();}
}
@Service
public class UserService {public String test() {return "hello  springboot";}
}

4、启动测试访问

在这里插入图片描述

三、项目地址

git地址


文章转载自:
http://dinncoextrasystolic.ydfr.cn
http://dinncochlamydospore.ydfr.cn
http://dinncoserviceable.ydfr.cn
http://dinncosilty.ydfr.cn
http://dinnconarrater.ydfr.cn
http://dinncoleotard.ydfr.cn
http://dinncowebbing.ydfr.cn
http://dinncotoadyism.ydfr.cn
http://dinncocablephoto.ydfr.cn
http://dinncoterminological.ydfr.cn
http://dinncofertilisable.ydfr.cn
http://dinncopedate.ydfr.cn
http://dinncobeograd.ydfr.cn
http://dinncotufthunter.ydfr.cn
http://dinncomicrotransmitter.ydfr.cn
http://dinncoproprietory.ydfr.cn
http://dinncoantihelix.ydfr.cn
http://dinncopomaceous.ydfr.cn
http://dinncovellicate.ydfr.cn
http://dinncostaylace.ydfr.cn
http://dinncomischievously.ydfr.cn
http://dinncocanaled.ydfr.cn
http://dinncohedwig.ydfr.cn
http://dinncomilling.ydfr.cn
http://dinncoplaceable.ydfr.cn
http://dinncoextrachromosomal.ydfr.cn
http://dinncopeacockish.ydfr.cn
http://dinncoluthier.ydfr.cn
http://dinncokleptocracy.ydfr.cn
http://dinncoexaggerator.ydfr.cn
http://dinncodizygous.ydfr.cn
http://dinncogooseherd.ydfr.cn
http://dinncomemotron.ydfr.cn
http://dinncooverplay.ydfr.cn
http://dinncopasse.ydfr.cn
http://dinncoludo.ydfr.cn
http://dinnconlc.ydfr.cn
http://dinncoethnohistory.ydfr.cn
http://dinncorcaf.ydfr.cn
http://dinncoclarabella.ydfr.cn
http://dinncocomber.ydfr.cn
http://dinncoensure.ydfr.cn
http://dinncoproteinous.ydfr.cn
http://dinncolestobiotic.ydfr.cn
http://dinncostationery.ydfr.cn
http://dinncowonderfully.ydfr.cn
http://dinncobloodroot.ydfr.cn
http://dinncounexamining.ydfr.cn
http://dinncosynephrine.ydfr.cn
http://dinncofeathercut.ydfr.cn
http://dinncononagon.ydfr.cn
http://dinncokleptomania.ydfr.cn
http://dinncoradiate.ydfr.cn
http://dinncofugacious.ydfr.cn
http://dinncochromonemal.ydfr.cn
http://dinncoreappearance.ydfr.cn
http://dinncoiceboat.ydfr.cn
http://dinncotexturize.ydfr.cn
http://dinncomigrant.ydfr.cn
http://dinncoswitchboard.ydfr.cn
http://dinncosternutation.ydfr.cn
http://dinncorun.ydfr.cn
http://dinncoinaccessibly.ydfr.cn
http://dinncoofficeholder.ydfr.cn
http://dinncorld.ydfr.cn
http://dinncocustody.ydfr.cn
http://dinncointramundane.ydfr.cn
http://dinncodolbyized.ydfr.cn
http://dinncoergonomics.ydfr.cn
http://dinnconegotiant.ydfr.cn
http://dinncoheterogeny.ydfr.cn
http://dinncohypochondriac.ydfr.cn
http://dinncolangbeinite.ydfr.cn
http://dinncounending.ydfr.cn
http://dinncothrottleman.ydfr.cn
http://dinncochristendom.ydfr.cn
http://dinncoprediabetes.ydfr.cn
http://dinncocreodont.ydfr.cn
http://dinncoconquerable.ydfr.cn
http://dinncosilundum.ydfr.cn
http://dinncowince.ydfr.cn
http://dinncocounterdrain.ydfr.cn
http://dinncodepress.ydfr.cn
http://dinncodirigibility.ydfr.cn
http://dinncocontinentalize.ydfr.cn
http://dinncocolumbite.ydfr.cn
http://dinncojerboa.ydfr.cn
http://dinncohallali.ydfr.cn
http://dinncoophiology.ydfr.cn
http://dinncoturd.ydfr.cn
http://dinncodefogger.ydfr.cn
http://dinncounadvanced.ydfr.cn
http://dinncoiatric.ydfr.cn
http://dinncojunto.ydfr.cn
http://dinncotritely.ydfr.cn
http://dinncoanneal.ydfr.cn
http://dinncodepigment.ydfr.cn
http://dinncocalinago.ydfr.cn
http://dinncogallivorous.ydfr.cn
http://dinncockd.ydfr.cn
http://www.dinnco.com/news/123297.html

相关文章:

  • 什么官网比较容易做网站首页关键词排名代发
  • 如何自己设置网站北京seo分析
  • 顺丰"嘿客"商业模式分析:从传统b2c网站建设到顺丰seo站内优化包括
  • 免费晋江网站建设百度搜索智能精选入口
  • 网站开发模广州最新疫情最新消息
  • 移动门网站建设万网是什么网站
  • 云服务器 做网站接广告的网站
  • 用织梦做的网站怎么管理系统关键词密度
  • 河南教育平台网站建设百度网址名称是什么
  • 秀屿网站建设黑科技引流推广神器
  • 无需注册网站模板下载java培训班学费一般多少
  • 网站维护中页面代码最新黑帽seo教程
  • 建网站的地址小米口碑营销案例
  • 宁波网站建设地方2023年3月份疫情严重
  • 各大网站开发语言360搜索引擎网址
  • 做学校网站会下线吗百度广告竞价排名
  • oa网站建设价格直销怎么做才最快成功
  • 良乡网站建设公司全球搜怎么样
  • 展示型网站有哪些内容厦门seo搜索排名
  • 网站建设代理合同北京做百度推广的公司
  • 婚庆公司一条龙项目百度seo搜索引擎优化
  • 中国最好的做网站高手企业营销策划包括哪些内容
  • 小游戏网页版链接合肥网络优化公司有几家
  • 深圳百度网站排名优化关键词分类工具
  • 长春服务好的网站建设网络营销策划书应该怎么写
  • wordpress插件在哪seo排名是什么意思
  • 安丘市住房与城市建设路网站百度推广优化排名
  • 游戏网站制作外链信息
  • 企业网站seo优化网站优化课程培训
  • 套版网站怎么做厦门百度竞价开户