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

cmd iis网站xuzhou网站制作

cmd iis网站,xuzhou网站制作,wordpress版权说明,国内网站建设推荐前言 Starter 是 Spring Boot 非常重要的一个硬核功能。 通过 Starter 我们可以快速的引入一个功能或模块#xff0c;而无须关心模块依赖的其它组件。关于配置#xff0c;Spring Boot 采用“约定大于配置”的设计理念#xff0c;Starter 一般都会提供默认配置#xff0c;只…前言 Starter 是 Spring Boot 非常重要的一个硬核功能。 通过 Starter 我们可以快速的引入一个功能或模块而无须关心模块依赖的其它组件。关于配置Spring Boot 采用“约定大于配置”的设计理念Starter 一般都会提供默认配置只有当我们有特殊需求的时候才需要在application.yaml里进行单独配置以覆盖掉默认配置。 例如我们开发一个 Web 应用需要用到 Spring MVC、Tomcat 等组件我们只需要依赖spring-boot-starter-web 即可Starter 已经包含了开发一个 Web 应用所需的所有组件和依赖包同时提供了 Web 服务的默认配置比如端口是 8080。 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId /dependency当我们有特殊需求时比如要修改服务端口才需要额外配置application.yaml server:port: 8090理解Starter Starter 是什么 Starter 是一个 Spring Boot 项目它包含了一个功能或模块依赖的所有组件。一般来说Starter 项目本身不包含任何代码只管理依赖。 Starter 要解决什么问题 没有 Starter 的时候我们要引入一个功能或模块首先要了解这个功能或模块依赖了哪些组件还要管理依赖的版本。依赖完以后还要配置所需的 bean以及其它一些配置文件的编写。整个过程极其繁琐门槛高。 Starter 解决了依赖和配置的问题它把所需的依赖打成一个包得益于 Spring Boot 自动装配同时解决了 bean 的配置问题。引入 Starter 就可以实现零配置或少量配置来使用相应的功能。 Starter 是怎么实现的 Starter 依赖 Spring Boot 自动装配的特性它首先包含模块依赖的所有第三方库再通过若干个XXXAutoConfiguration 的自动配置类来声明模块所需的 BeanSpring Boot 程序启动时会自动加载这些配置类把对应的 Bean 注册到容器以实现某个功能。 Starter实战 通过编写一个我们自己的 Starter 来进一步理解其原理。 需求编写一个可以操作 Redis 的客户端 Starter。 项目结构 redis-client- client- redis-spring-boot- redis-spring-boot-starter- redis-spring-boot-autoconfigure模块介绍 模块说明redis-client父项目管理依赖clientRedis 客户端核心模块redis-spring-bootRedis 客户端和 Spring Boot 整合模块redis-spring-boot-starterRedis 客户端启动器redis-spring-boot-autoconfigureRedis 客户端自动装配模块核心 redis-client 基础模块没有代码主要管理依赖。因为要操作 Redis这里引入 jedis。 dependencyManagementdependenciesdependencygroupIdio.redis/groupIdartifactIdclient/artifactIdversion${project.version}/version/dependencydependencygroupIdredis.clients/groupIdartifactIdjedis/artifactIdversion4.4.6/version/dependency/dependencies /dependencyManagementclient client 是 Redis 客户端核心模块提供了操作 Redis 的客户端实现。它应该被设计成可以脱离 Spring 独立运行的所以这个项目不应该依赖 Spring 任何东西。 首先抽象一个客户端接口出于简单考虑这里只提供 get、set 方法 public interface RedisClient {void set(String key, String value);String get(String key); }同时提供一个默认实现这里只是对 jedis 做一层包装 public class DefaultRedisClient implements RedisClient {private final Jedis jedis;public DefaultRedisClient(Jedis jedis) {this.jedis jedis;}Overridepublic void set(String key, String value) {jedis.set(key, value);}Overridepublic String get(String key) {return jedis.get(key);} }再提供一个工厂类用来创建客户端实例 public class RedisClientFactory {public static RedisClient create(String host, int port, String user, String password, int database) {JedisClientConfig config DefaultJedisClientConfig.builder().user(user).password(password).database(database).build();Jedis jedis new Jedis(host, port, config);return new DefaultRedisClient(jedis);} }至此client 模块就完成了而且是可以直接跑的无需 Spring。 redis-spring-boot 为了开发者更加方便的在 Spring Boot 环境下使用我们的 Redis Client我们要和 Spring Boot 做一个整合为此再单独新建一个 redis-spring-boot 模块。它是一个父模块主要管理依赖 dependencyManagementdependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter/artifactIdversion2.7.18/version/dependencydependencygroupIdio.redis/groupIdartifactIdredis-spring-boot-autoconfigure/artifactIdversion${project.version}/version/dependency/dependencies /dependencyManagementredis-spring-boot-starter 我们的 Starter 模块也就是开发者要引入的唯一一个模块。模块的命名上大家要注意spring-boot-starter-XXX 这种前缀是 Spring Boot 官方保留的名字我们不要用建议用XXX-spring-boot-starter 风格命名。 Starter 模块一般没有代码只管理依赖的组件这里主要是引入我们的自动装配模块 dependenciesdependencygroupIdio.redis/groupIdartifactIdredis-spring-boot-autoconfigure/artifactId/dependency /dependenciesredis-spring-boot-autoconfigure Redis Client 与 Spring Boot 整合的自动装配模块也是我们这个示例中的核心模块。先看依赖 dependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter/artifactId/dependencydependencygroupIdio.redis/groupIdartifactIdclient/artifactId/dependency /dependenciesRedisClientAutoConfiguration自动配置类Spring Boot 启动时会自动加载。它的加载是有条件的首先得是 ClassPath 下包含 RedisClient.class没有这个类我们就没法自动装配其次是redis.enabled 不配置或者必须为 true 才会启用否则是禁用的。 Configuration ConditionalOnClass(RedisClient.class) ConditionalOnProperty(prefix redis,name {enabled},matchIfMissing true ) EnableConfigurationProperties(RedisClientProperties.class) public class RedisClientAutoConfiguration {Beanpublic RedisClient redisClient(RedisClientProperties properties) {return RedisClientFactory.create(properties.getHost(), properties.getPort(),properties.getUser(), properties.getPassword(), properties.getDatabase());} }自动配置类还开启了自动配置属性类是 RedisClientProperties。按照“约定大于配置”的理念我们提供了默认配置开发者也可以选择覆盖默认配置 ConfigurationProperties(prefix redis,ignoreUnknownFields true ) public class RedisClientProperties {private String host localhost;private int port 6379;private String user;private String password;private int database 0;// 忽略 getter、setter }最后要想办法让 Spring Boot 加载我们的配置类。按照 Spring Boot 自动装配的规则我们编写META-INF/spring.factories文件 org.springframework.boot.autoconfigure.EnableAutoConfiguration\io.redis.client.spring.boot.autoconfigure.RedisClientAutoConfiguration至此我们的 Starter 就开发完毕了把它安装到 Maven 仓库就可以给其它小伙伴用了。 测试一下 新建一个测试项目引入依赖 dependenciesdependencygroupIdio.redis/groupIdartifactIdredis-spring-boot-starter/artifactIdversion1.0-SNAPSHOT/version/dependency /dependencies编写一个启动类注入 RedisClient尝试读取一下数据是成功的 SpringBootApplication public class Application {AutowiredRedisClient redisClient;public static void main(String[] args) {ConfigurableApplicationContext context SpringApplication.run(Application.class, args);RedisClient redisClient context.getBean(Application.class).redisClient;redisClient.set(haha, xixi);System.err.println(redisClient.get(haha));} }尾巴 Starter 是 Spring Boot 框架中的一个重要概念它提供了一种便捷的方式来配置和使用特定功能的 Spring Boot 应用程序。通常一个 Starter 是一个包含了一组相关依赖和配置的项目目的是为了简化应用程序的开发和部署过程。 Starter 的设计目标是通过隐藏繁琐的配置细节和依赖声明使开发者能够更专注于业务逻辑的实现。当你想要使用某个功能或集成某个组件时只需引入相应的 Starter 依赖Spring Boot 就会自动配置相关的组件并提供默认的配置选项大大减少了手动配置的工作量。 Starter 依赖于 Spring Boot 自动装配的特性理解了自动装配你就理解了 Starter。
http://www.zqtcl.cn/news/662008/

相关文章:

  • 简述网站设计流程沁水做网站
  • 南京公司网站建设怎么收费获奖网页设计
  • 网站域名试用期水墨风格网站源码
  • 长沙网站开长沙手机网站建设哪些内容
  • 网站建设算固定资产吗做泵阀生意到哪个网站
  • 佛山网站建设定制杭州人防质监站网址
  • 什么网站可以做微官网定制小程序制作一个需要多少钱
  • 扒下来的网站怎么做修改什么样是权网站重高的
  • 淘宝客做网站链接潍坊网站建设wfzhy
  • 怎样做二维码链接到网站上做的比较好的美食网站有哪些
  • 自动化科技产品网站建设响应式博客wordpress
  • 个人建站如何赚钱男人的好看网
  • 门户网站建设管理工作作一手房用什么做网站
  • 网站建设优化服务案例三合一网站程序
  • 网站长尾词关于制作网站的方案
  • 做二手衣服的网站有哪些wordpress单本小说采集
  • 曲靖市建设局网站品牌营销咨询公司是做什么的
  • wordpress网站统计代码放哪个文件putty搭建wordpress
  • 桦南县建设局网站天坛装修公司口碑怎么样
  • 网站的建设求职简历网站开发与维护价格
  • 网站空间备份站长网站优点
  • 房产网站做那个比较好网页设计属于前端吗
  • 衡水企业网站建设费用html5网页设计教程
  • 用wp系统做网站网站有收录没排名
  • 网站源码程序下载ios开发软件
  • 设计好的网站什么是企业网站策划案
  • 北京网站建设亿玛酷适合5传奇网站装备动态图怎么做
  • 多平台网站设计实例3d效果图什么网站做的好
  • 58同城西安网站建设购物网站前端浮动特效怎么做
  • asp网站模板源码wordpress 画图插件