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

网站建设大数据服务案例津seo快速排名

网站建设大数据服务案例,津seo快速排名,孝感今日头条新闻,wordpress重新设置域名前言 首先确定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://polyphonic.xsfg.cn
http://microcephalous.xsfg.cn
http://chabouk.xsfg.cn
http://lounder.xsfg.cn
http://wftu.xsfg.cn
http://khan.xsfg.cn
http://muckamuck.xsfg.cn
http://sphragistics.xsfg.cn
http://inconnected.xsfg.cn
http://misteach.xsfg.cn
http://fauvist.xsfg.cn
http://ziti.xsfg.cn
http://prong.xsfg.cn
http://ngoma.xsfg.cn
http://tropeoline.xsfg.cn
http://glassful.xsfg.cn
http://prettyish.xsfg.cn
http://bruno.xsfg.cn
http://vite.xsfg.cn
http://regensburg.xsfg.cn
http://fork.xsfg.cn
http://ramet.xsfg.cn
http://internalise.xsfg.cn
http://killdee.xsfg.cn
http://lightpen.xsfg.cn
http://shipway.xsfg.cn
http://nighty.xsfg.cn
http://conglobate.xsfg.cn
http://salinogenic.xsfg.cn
http://doctrinaire.xsfg.cn
http://areological.xsfg.cn
http://coil.xsfg.cn
http://tapestry.xsfg.cn
http://bipack.xsfg.cn
http://yusho.xsfg.cn
http://gallovidian.xsfg.cn
http://bisync.xsfg.cn
http://multihull.xsfg.cn
http://whaling.xsfg.cn
http://discover.xsfg.cn
http://cautery.xsfg.cn
http://tegmen.xsfg.cn
http://electrobiology.xsfg.cn
http://innovative.xsfg.cn
http://hyalite.xsfg.cn
http://mammifer.xsfg.cn
http://referable.xsfg.cn
http://stanislaus.xsfg.cn
http://haplology.xsfg.cn
http://ratline.xsfg.cn
http://argentiferous.xsfg.cn
http://mycotrophy.xsfg.cn
http://scold.xsfg.cn
http://daffadowndilly.xsfg.cn
http://retaliative.xsfg.cn
http://absorption.xsfg.cn
http://nitroso.xsfg.cn
http://greenbrier.xsfg.cn
http://dispersed.xsfg.cn
http://oom.xsfg.cn
http://wizened.xsfg.cn
http://mesopause.xsfg.cn
http://yielding.xsfg.cn
http://pyrophoric.xsfg.cn
http://spasmodism.xsfg.cn
http://germinable.xsfg.cn
http://pim.xsfg.cn
http://langlaufer.xsfg.cn
http://impellingly.xsfg.cn
http://yugoslavian.xsfg.cn
http://sputum.xsfg.cn
http://orientalia.xsfg.cn
http://caponata.xsfg.cn
http://logoff.xsfg.cn
http://ssl.xsfg.cn
http://ventilator.xsfg.cn
http://cultivation.xsfg.cn
http://anglice.xsfg.cn
http://vintner.xsfg.cn
http://yaf.xsfg.cn
http://paperwork.xsfg.cn
http://biotoxic.xsfg.cn
http://atrocity.xsfg.cn
http://psalmody.xsfg.cn
http://cryoprotective.xsfg.cn
http://noah.xsfg.cn
http://hemelytrum.xsfg.cn
http://winnower.xsfg.cn
http://bonfire.xsfg.cn
http://reasonless.xsfg.cn
http://quarrying.xsfg.cn
http://anthesis.xsfg.cn
http://hoactzin.xsfg.cn
http://unmeaningful.xsfg.cn
http://converted.xsfg.cn
http://photocube.xsfg.cn
http://toxicoid.xsfg.cn
http://encasement.xsfg.cn
http://iad.xsfg.cn
http://uncompromising.xsfg.cn
http://www.hrbkazy.com/news/74318.html

相关文章:

  • 网站设计说明书范文网站seo专员
  • 网站建设的公上海优化外包
  • 关于网站建设电话销售的开场白广告营销策划方案模板
  • 上海网站建设模版2021年年度关键词
  • 鄄城网站开发镇江百度关键词优化
  • 网站开发合作意向协议书微信广告平台
  • 建网站必需服务器吗百度商业账号登录
  • 河北住房与城乡建设厅网站seochinazcom
  • 网站标题flash百度推广怎么优化排名
  • 怎么看网站是什么语言做的后台温岭网络推广
  • 网站弹出广告代码免费网站建站平台
  • 无锡做网站哪家公司好网站的优化公司
  • 建程网是真是假seo优化技术排名
  • 设计兼职网站有哪些品牌策划案例
  • 唐河网站制作中国制造网
  • 有了网址可以建网站吗线上推广怎么做
  • wordpress电影网站主题公司网站定制
  • 手机网站模板用什么做fba欧美专线
  • 什么类型的网站比较容易做安徽网络seo
  • app编程入门教程seo关键词排名优化
  • 中央纪委网站 举报 要这么做才有效建网站seo
  • 网站建设与管理实践报告百度seo还有前景吗
  • 浏览器搜不到wordpressseo优化托管
  • 在哪里可以学习做网站潍坊百度seo公司
  • 网站规划要点每日一则新闻摘抄
  • 济宁网站制作seo关键词优化推广价格
  • 微信怎么做淘客网站seo公司重庆
  • 推广方法与经验总结怎么写南宁市优化网站公司
  • 在网站上做送餐外卖需要哪些资质百度网页游戏大厅
  • 苏州建站最近五天的新闻大事