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

公司网站建设注意点网络工程的定义

公司网站建设注意点,网络工程的定义,国内比较大的源码网站,直播电商平台有哪些在之前的《Spring Cloud构建微服务架构#xff1a;分布式配置中心》一文中#xff0c;我们介绍的Spring Cloud Server配置中心采用了Git的方式进行配置信息存储。这一设计巧妙的利用Git自身机制以及其他具有丰富功能的Git服务端产品#xff0c;让Spring Cloud Server在配置存…在之前的《Spring Cloud构建微服务架构分布式配置中心》一文中我们介绍的Spring Cloud Server配置中心采用了Git的方式进行配置信息存储。这一设计巧妙的利用Git自身机制以及其他具有丰富功能的Git服务端产品让Spring Cloud Server在配置存储和管理的上避开了很多与管理相关的复杂实现使其具备了配置中心存储配置和读取配置的基本能力而更上层的管理机制由于不具备普遍适用性所以Spring Cloud Server并没有自己去实现这部分内容而是通过Git服务端产品来提供一部分实现如果还需要更复杂的功能也能自己实现与定义。即便如此对于Spring Cloud Server默认使用Git来存储配置的方案一直以来还是饱受争议。所以本文将介绍一下Spring Cloud Config从Edgware版本开始新增的一种配置方式采用数据库存储配置信息。 构建配置中心服务端 第一步创建一个基础的Spring Boot项目在pom.xml中引入几个主要依赖 spring-cloud-config-server配置中心的基础依赖spring-boot-starter-jdbc由于需要访问数据库所以需要加载jdbc的依赖mysql-connector-javaMySQL数据库的连接包flyway-core该内容非强制主要用来管理schema如果您不了解可以看一下这篇文章 parent groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-parent/artifactId version1.5.11.RELEASE/version relativePath//parentdependencies dependency groupIdorg.springframework.cloud/groupId artifactIdspring-cloud-config-server/artifactId /dependency dependency groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-jdbc/artifactId /dependency dependency groupIdorg.flywaydb/groupId artifactIdflyway-core/artifactId version5.0.3/version /dependency dependency groupIdmysql/groupId artifactIdmysql-connector-java/artifactId version5.1.21/version /dependency/dependenciesdependencyManagement dependencies dependency groupIdorg.springframework.cloud/groupId artifactIdspring-cloud-dependencies/artifactId versionEdgware.SR3/version typepom/type scopeimport/scope /dependency /dependencies/dependencyManagement第二步准备schema创建文件。在resources下创建schema目录并加入V1__Base_version.sql文件具体内容如下 CREATE TABLE properties ( id int(11) NOT NULL, key varchar(50) NOT NULL, value varchar(500) NOT NULL, application varchar(50) NOT NULL, profile varchar(50) NOT NULL, label varchar(50) NOT NULL, PRIMARY KEY (id)) ENGINEInnoDB DEFAULT CHARSETutf8;该脚本会在程序运行时由flyway自动执行 第三步创建应用主类具体如下 EnableConfigServerSpringBootApplicationpublic class ConfigServerBootstrap { public static void main(String[] args) { ApplicationContext context SpringApplication.run(ConfigServerBootstrap.class); // 测试用数据仅用于本文测试使用 JdbcTemplate jdbcTemplate context.getBean(JdbcTemplate.class); jdbcTemplate.execute(delete from properties); jdbcTemplate.execute(INSERT INTO properties VALUES(1, com.didispace.message, test-stage-master, config-client, stage, master)); jdbcTemplate.execute(INSERT INTO properties VALUES(2, com.didispace.message, test-online-master, config-client, online, master)); jdbcTemplate.execute(INSERT INTO properties VALUES(3, com.didispace.message, test-online-develop, config-client, online, develop)); jdbcTemplate.execute(INSERT INTO properties VALUES(4, com.didispace.message, hello-online-master, hello-service, online, master)); jdbcTemplate.execute(INSERT INTO properties VALUES(5, com.didispace.message, hello-online-develop, hello-service, online, develop)); }}这里增加了一些测试用数据以便于后续的配置读取验证。 第四步配置application.properties具体内容如下 spring.application.nameconfig-server-dbserver.port10020spring.profiles.activejdbcspring.cloud.config.server.jdbc.sqlSELECT KEY, VALUE from PROPERTIES where APPLICATION? and PROFILE? and LABEL?spring.datasource.urljdbc:mysql://localhost:3306/config-server-dbspring.datasource.usernamerootspring.datasource.passwordspring.datasource.driver-class-namecom.mysql.jdbc.Driverflyway.locations/schema这里主要涉及几个配置 spring.profiles.activejdbc必须设置将配置中心的存储实现切换到jdbc的方式spring.cloud.config.server.jdbc.sql非必须这里由于采用mysql数据源key、value是保留关键词原生的实现语句会报错所以需要重写一下这句查询语句如果存储的表结构设计不同于上面准备的内容也可以通过这个属性的配置来修改配置的获取逻辑spring.datasource.*存储配置信息的数据源配置这里采用mysql开发者根据自己实际情况修改flyway.locationsflyway加载schema创建sql的位置 服务端配置验证 完成了上一节内容之后我们就已经构建一个通过数据酷来存储配置内容的配置中心了下面我们可以通过配置中心暴露的端点来尝试读取配置。 第一步先将上面构建的配置中心启动起来。 第二步验证配置信息获取 curl http://localhost:10020/config-client/stage/获取信息config-client服务stage环境的配置内容根据上面的数据准备我们会获得如下返回内容 { name: config-client, profiles: [ stage ], label: null, version: null, state: null, propertySources: [ { name: config-client-stage, source: { com.didispace.message: test-stage-master } } ]}curl http://localhost:10020/hello-service/stage/develop获取信息hello-service服务stage环境develop标签的配置内容根据上面的数据准备我们会获得如下返回内容 { name: hello-service, profiles: [ online ], label: develop, version: null, state: null, propertySources: [ { name: hello-service-online, source: { com.didispace.message: hello-online-develop } } ]}关于如何访问Spring Cloud Config构建配置中心获取配置信息的详细内容可以查看前文《Spring Cloud构建微服务架构分布式配置中心》本文不做详细介绍。 总结 本文主要具体介绍了在Spring Cloud Config在Edgware版本开始新增的JDBC存储的使用思路具体使用实际上还有很多可以优化的空间比如索引的优化、查询语句的优化如果还需要进一步定制管理对于表结构的优化也是很有必要的。 最后安利一个基于Spring Cloud Config的配置管理项目https://github.com/dyc87112/spring-cloud-config-admin正在紧锣密鼓的开发中尽情期待 本文示例 读者可以根据喜好选择下面的两个仓库中查看config-server-db和config-client两个项目 Githubhttps://github.com/dyc87112/SpringCloud-Learning/Giteehttps://gitee.com/didispace/SpringCloud-Learning/ 如果您对这些感兴趣欢迎star、follow、收藏、转发给予支持
http://www.yutouwan.com/news/452534/

相关文章:

  • .vip网站 被百度收录做网站必须原创吗
  • 检查网站是否做301网站建设费属于服务类么
  • 中山 网站制作新农村建设管理网站
  • 网站后台维护费用壁纸公司网站源码
  • 第二季企业网站开发成都网站建设培训班
  • 酒店网站制作vs sql server网站开发
  • 网站开发技术规范商务平台搭建
  • 绵阳远腾建设网站好三网网站
  • 做网站需要有平面排版网站
  • 贵阳网站建设兼职网站建设的职称
  • 服装公司电商网站建设规划织梦文章采集到wordpress
  • 江苏seo策略九江网站建设优化
  • 如何上传文件到自己的网站开鲁网站seo转接
  • 小学校园网站怎么建设百度爱采购网站官网
  • wordpress 本地部署手机网站seo教程下载
  • 住建部网站统计城乡建设统计信息系统登录博物馆建设网站的作用
  • 网站修改器建设大厦网站
  • 大庆建设中专网站制作婚恋网站
  • 网站做seo需要大量文章计算机培训机构一般多少钱
  • 北京建设网站的公司做网站有什么意义
  • 外贸做网站的好处嵌入式应用软件开发流程
  • 大数据 做网站流量统计wordpress 语种顺序
  • 快站怎么搭建淘客链接济南做网站建设公司
  • 如何提高网站在搜索引擎中的排名泉州哪里有搭建网站的公司
  • 小学学校网站网站flash制作教程
  • 烟台建网站公司价格云之创网站建设
  • 中英文企业网站女装网站建设规划书怎么写
  • asp.net 做网站文章是怎么存储的企业网站网址
  • dw代码做网站wordpress网页优化
  • 做宣传的网站有哪些查工作单位的网站