首页 文章 精选 留言 我的

精选列表

搜索[c 14],共10000篇文章
优秀的个人博客,低调大师

(四)spring cloud微服务架构b2b2c电子商务 - common-service 项目构建过程

我们将对common-service整个项目进行剖析,将整个构建的流程给记录下来,让更多的关注者来参考学习。 首先在构建spring cloud的common-service之前,我们需要准备的技术: Maven(项目构建)、Spring Boot、Spring Cloud、微服务概念、去中心化思想、分布式等,针对于common-service的顶级项目,这里我们主要使用Maven来构建,闲话少说,我们直接上代码是最直观的。 创建一个Maven的顶级项目,其中pom.xml文件配置如下: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-parent</artifactId> <version>Dalston.RELEASE</version> <relativePath /> </parent> <groupId>com.ml.honghu</groupId> <artifactId>particle-commonservice</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>pom</packaging> <name>particle-commonservice</name> <description>particle-commonservice project for Spring Boot</description> <modules> <module>particle-commonservice-config</module> <module>particle-commonservice-eureka</module> <module>particle-commonservice-mq</module> <module>particle-commonservice-cache</module> <module>particle-commonservice-sso</module> <module>particle-commonservice-apigateway</module> <module>particle-commonservice-zipkin</module> <module>particle-commonservice-admin</module> <module>particle-commonservice-turbine</module> <module>particle-commonservice-combine</module> <module>particle-commonservice-sequence</module> </modules> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <!-- 框架通用包版本设置 --> <validator.version>5.3.4.Final</validator.version> <shiro.version>1.2.3</shiro.version> <druid.version>1.0.26</druid.version> <mybatis-spring.version>1.2.2</mybatis-spring.version> <shiro.version>1.2.3</shiro.version> <druid.version>1.0.11</druid.version> <ehcache.version>2.6.9</ehcache.version> <ehcache-web.version>2.0.4</ehcache-web.version> <sitemesh.version>2.4.2</sitemesh.version> <activiti.version>5.15.1</activiti.version> <wink.version>1.4</wink.version> <sso.client.version>3.4.1</sso.client.version> --> <!-- 通用工具包版本设置 --> <slf4j.version>1.7.7</slf4j.version> <commons-lang3.version>3.3.2</commons-lang3.version> <commons-io.version>2.4</commons-io.version> <commons-codec.version>1.9</commons-codec.version> <commons-fileupload.version>1.3.1</commons-fileupload.version> <commons-beanutils.version>1.9.1</commons-beanutils.version> <fastjson.version>1.1.40</fastjson.version> <xstream.version>1.4.7</xstream.version> <guava.version>17.0</guava.version> <dozer.version>5.5.1</dozer.version> <email.version>1.4.7</email.version> <poi.version>3.9</poi.version> <cglib.version>3.2.5</cglib.version> <!-- aliyun --> <aliyun-sdk-oss.version>2.6.0</aliyun-sdk-oss.version> <aliyun-sdk-openservices-ons.version>1.2.7.Final</aliyun-sdk-openservices-ons.version> <com.ml.honghu.componet.version>0.0.1-SNAPSHOT</com.ml.honghu.componet.version> <spring-boot-admin.version>1.5.1</spring-boot-admin.version> <fastjson.version>1.2.35</fastjson.version> </properties> <dependencyManagement> <dependencies> <!-- spring cloud --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Dalston.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>org.jasig.cas.client</groupId> <artifactId>cas-client-core</artifactId> <version>3.4.1</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.5.0</version> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server</artifactId> <version>${spring-boot-admin.version}</version> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server-ui</artifactId> <version>${spring-boot-admin.version}</version> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server-ui-hystrix</artifactId> <version>${spring-boot-admin.version}</version> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server-ui-turbine</artifactId> <version>${spring-boot-admin.version}</version> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server-ui-login</artifactId> <version>${spring-boot-admin.version}</version> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server-ui-activiti</artifactId> <version>${spring-boot-admin.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.25</version> </dependency> <dependency> <groupId>com.ml.honghu</groupId> <artifactId>component-base</artifactId> <version>${com.ml.honghu.componet.version}</version> </dependency> <dependency> <groupId>com.ml.honghu</groupId> <artifactId>component-redis</artifactId> <version>${com.ml.honghu.componet.version}</version> </dependency> <dependency> <groupId>com.ml.honghu</groupId> <artifactId>component-utils</artifactId> <version>${com.ml.honghu.componet.version}</version> </dependency> <dependency> <groupId>com.ml.honghu</groupId> <artifactId>component-sequence-api</artifactId> <version>${com.ml.honghu.componet.version}</version> </dependency> <dependency> <groupId>com.ml.honghu</groupId> <artifactId>component-admin-ui-zipkin</artifactId> <version>${com.ml.honghu.componet.version}</version> </dependency> <dependency> <groupId>com.ml.honghu</groupId> <artifactId>component-admin-ui-route</artifactId> <version>${com.ml.honghu.componet.version}</version> </dependency> <dependency> <groupId>com.ml.honghu</groupId> <artifactId>component-zuul-label</artifactId> <version>${com.ml.honghu.componet.version}</version> </dependency> </dependencies> </dependencyManagement> </project> 当前的pom.xml文件引入了spring cloud相关版本配置,通用工具版本配置,honghu相关组件配置(因为其他的系统服务项目依赖于相关的组件,组件项目也是后面来创建的) 从现在开始,我这边会将近期研发的spring cloud微服务云架构的搭建过程和精髓记录下来,帮助更多有兴趣研发spring cloud框架的朋友,大家来一起探讨spring cloud架构的搭建过程及如何运用于企业项目。

优秀的个人博客,低调大师

java B2B2C电子商务平台分析之八--配置中心svn示例和refresh

国内很多公司都使用的svn来做代码的版本控制,我们先介绍以下如何使用svn+Spring Cloud Config来做配置中心。愿意了解源码的朋友直接求求交流分享技术:二一四七七七五六三三 svn版本同样先示例server端的代码,基本步骤一样。 1、添加依赖 <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency> <dependency> <groupId>org.tmatesoft.svnkit</groupId> <artifactId>svnkit</artifactId> </dependency> </dependencies> 需要多引入svnkitr包 2、配置文件 server: port: 8001 spring: cloud: config: server: svn: uri: http://192.168.0.6/svn/repo/config-repo username: username password: password default-label: trunk profiles: active: subversion application: name: spring-cloud-config-server 和git版本稍有区别,需要显示声明subversion. 3、启动类启动类没有变化,添加@EnableConfigServer激活对配置中心的支持 @EnableConfigServer @SpringBootApplication public class ConfigServerApplication { public static void main(String[] args) { SpringApplication.run(ConfigServerApplication.class, args); } } 4、测试服务端测试 访问:http :/ /localhost:8001/neo-config-dev.properties,返回:neo.hello: hello im dev,说明服务端可以正常读取到svn代码库中的配置信息。修改配置文件neo-config-dev.properties中配置信息为:neo.hello=hello im dev update,再次在浏览器访问http :/ /localhost:8001/neo-config-dev.properties,返回:neo.hello: hello im dev update。说明server端会自动读取最新提交的内容 客户端测试 客户端直接使用上一篇示例项目spring-cloud-config-client来测试,配置基本不用变动。启动项目后访问:http :/ /localhost:8002/hello,返回:hello im dev update说明已经正确的从server端获取到了参数。同样修改svn配置并提交,再次访问http :/ /localhost:8002/hello``依然获取的是旧的信息,和git版本的问题一样。 refresh现在来解决上一篇的遗留问题,这个问题在svn版本中依然存在。Spring Cloud Config分服务端和客户端,服务端负责将git(svn)中存储的配置文件发布成REST接口,客户端可以从服务端REST接口获取配置。但客户端并不能主动感知到配置的变化,从而主动去获取新的配置。客户端如何去主动获取新的配置信息呢,springcloud已经给我们提供了解决方案,每个客户端通过POST方法触发各自的/refresh。 修改spring-cloud-config-client项目已到达可以refresh的功能。 1、添加依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> 增加了spring-boot-starter-actuator包,spring-boot-starter-actuator是一套监控的功能,可以监控程序在运行时状态,其中就包括/refresh的功能。 2、 开启更新机制需要给加载变量的类上面加载@RefreshScope,在客户端执行/refresh的时候就会更新此类下面的变量值。 @RestController @RefreshScope // 使用该注解的类,会在接到SpringCloud配置中心配置刷新的时候,自动将新的配置更新到该类对应的字段中。 class HelloController { @Value("${neo.hello}") private String hello; @RequestMapping("/hello") public String from() { return this.hello; } } 3、测试springboot 1.5.X 以上默认开通了安全认证,所以需要在配置文件application.properties添加以下配置management.security.enabled=falseOK 这样就改造完了,以post请求的方式来访问http://localhost:8002/refresh就会更新修改后的配置文件。我们再次来测试,首先访问http :/ /localhost:8002/hello,返回:hello im dev,我将库中的值修改为hello im dev update。在win上面打开cmd执行curl -X POST http://localhost:8002/refresh,返回["neo.hello"]说明已经更新了neo.hello的值。 我 们 再次访问http:/ /localhost:8002/hello,返回:hello im dev update,客户端已经得到了最新的值。 每次手动刷新客户端也很麻烦,有没有什么办法只要提交代码就自动调用客户端来更新呢,github的webhook是一个好的办法。 4、webhookWebHook是当某个事件发生时,通过发送http post请求的方式来通知信息接收方。Webhook来监测你在Github.com上的各种事件,最常见的莫过于push事件。如果你设置了一个监测push事件的Webhook,那么每当你的这个项目有了任何提交,这个Webhook都会被触发,这时Github就会发送一个HTTP POST请求到你配置好的地址。 如此一来,你就可以通过这种方式去自动完成一些重复性工作,比如,你可以用Webhook来自动触发一些持续集成(CI)工具的运作,比如Travis CI;又或者是通过 Webhook 去部署你的线上服务器。下图就是github上面的webhook配置。 Payload URL:触发后回调的URLContent type:数据格式,两种一般使用jsonSecret:用作给POST的body加密的字符串。采用HMAC算法events:触发的事件列表。events事件类型 描述push 仓库有push时触发。默认事件create 当有分支或标签被创建时触发delete 当有分支或标签被删除时触发svn也有类似的hook机制,每次提交后会触发post-commit脚本,我们可以在这里写一些post请求。这样我们就可以利用hook的机制去触发客户端的更新,但是当客户端越来越多的时候hook支持的已经不够优雅,另外每次增加客户端都需要改动hook也是不现实的。其实Spring Cloud给了我们更好解决方案,后面文章来介绍。 技术架构图如下: 资料和源码来源

优秀的个人博客,低调大师

C#序列化的时候将实体进行驼峰命名(第一个首字母小写)

引用的程序集: NewtonSoft 第一种:使用对象的字段属性设置JsonProperty来实现(不推荐,因为需要手动的修改每个字段的属性) public class UserInfo { [JsonProperty("id")] public int Id{ set; get; } [JsonProperty("userName")] public string UserName{ set; get; } } 第二种:使用newtonsoft.json来设置格式化的方式(推荐使用) var user = new UserInfo { UserName = "john", Id = 19 }; var serializerSettings = new JsonSerializerSettings { // 设置为驼峰命名 ContractResolver = new CamelCasePropertyNamesContractResolver() }; var userStr = JsonConvert.SerializeObject(user, serializerSettings); var data = JsonConvert.DeserializeObject<UserInfo>(userStr); Console.WriteLine(data.UserName + " " + data.Id); 转换后的JSON 序列化.png 驼峰命名,反列化也一样能够映射到实体上面 反序列化.png

优秀的个人博客,低调大师

C#的Winform中OpenFileDialog对话框Filter属性设置包含特定字符,使用正则表达式

OpenFileDialog对话框的Filter属性说明: 首先观察Filter属性的组成部分:“Word文件|*.doc”,前面的“Word文件”成为标签,是一个可读的字符串,可以自定定义,“|*.doc”是筛选器,表示筛选文件夹中后缀名为.doc的文件,“*”表示匹配Word文件名称的字符串。 OK,下面说说我们经常要用到的几种情况: 1.Filter是null或Empty,表示显示所有文件,并总会显示文件夹 2.需要筛选特定的文件,设置Filter属性为“标签|*.后缀”,按照这个格式设置,标签可以自定义,是字符串即可,后缀表示你需要筛选的文件后缀,例如“.txt、.doc”等 3.需要筛选多种文件,比方说需要筛选图片文件,但是图片文件的后缀有几种,例如jpg、png、gif等,当需要同时筛选这些文件,设置Filter属性为“标签|*.jpg;*.png;*.gif”,注意:只是在筛选器中多添加了几个后缀,不同后缀之间使用分号隔开 4.当需要筛选多种文件,但是不同时将它们全部列出来,只有用户分别通过下拉列表选择需要的文件类型时,才进行筛选。这种情况下只需要多设置几个筛选器即可,filter属性设置如下:“标签1|*.jpg|标签2|.png|标签3|.gif”。注意:不同的筛选器之间使用“|”分隔即可。 Filter属性类似与正则表达式,试用*表示匹配文件名的字符,使用“.后缀”匹配文件的后缀名,通过连接后缀(试用;号将需要的后缀分开)表示同时筛选所有的符合后缀的文件,通过“|”连接不同的筛选器表示通过用户选择后缀名称来进行文件筛选. 比如你要筛选word文件,后缀为".doc",如果筛选出的.doc类型的word文件较多,使用正则表达式能很快找到你想要的word文件 1 OpenFD.Filter ="word|*.docx"; 2 3 OpenFD.Filter ="word|*开题报告*.docx"; 第1行中 | 后的 *.docx 表示匹配全部的以 .docx结尾的文件, 第3行中 | 后的 *开题报告*.docx 表示匹配文件名称中包含 “ 开题报告”的并且以 .docx 结尾的文件

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册
修改密码
忘记密码