zuul入门
zuul是spring cloud的网关组件,用户在微服务中提供一个统一的对外接口,官方对zuul的说明是
Zuul is an edge service that provides dynamic routing, monitoring, resiliency, security, and more.
zuul是spring cloud的网关组件,用户在微服务中提供一个统一的对外接口,官方对zuul的说明是
Zuul is an edge service that provides dynamic routing, monitoring, resiliency, security, and more.
使用maven管理项目时,完成开发后需要把项目发布到maven私服上去。
手动SNAPSHOT
版本开发时执行mvn clean deploy
就可以部署到私服上。
在开发是还会需要SNAPSHOT版本和RELEASE版本可以用mvn versions:set -DnewVersion=0.1.1-SNAPSHOT
进行更改版本号
当然maven还有更好的管理插件进行RELEASE管理maven-release-plugin
公司服务器ip网段与电脑网段不同。于是要通过配置路由去访问。
每次开机都要重新执行一遍添加路由的脚本,
1 | sudo route add -net 192.168.103.0/24 gw 192.168.8.118 |
于是就把脚本放入开机启动自动执行
只需要在 /etc/init.d/
文件夹下新建一个文件
*** 添加执行权限 ***
*** 在文件开头添加 ***
1 | @Component |
1 | //通过ConfigurableListableBeanFactory可以注册一个bean |
1 | //实现BeanPostProcessor接口 |
在自定义Appender
时,设置属性可以直接通过logback.xml
进行设置,但是枚举对象,默认的处理方法不能处理,
这事可以自己定义一个新的解析规则
1 | public class DIYAppender extends OutputStreamAppender { |
可以在logback.xml
的appender节点中直接进行设置,如果属性是对象可以提供class
属性进行设置
1 | <newRule pattern="configuration/appender/enumAttr" class="enumObjAction"/> |
有时候想要扫描某一个包下的类,spring提供一个一扫描的类,org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider
这个类的findCandidateComponents
就是扫描的方法。通过自己继承这个类,再提供类的过滤条件。就可以了
还可以继承它的子类org.springframework.context.annotation.ClassPathBeanDefinitionScanner
需要两个过滤设置。因为扫描的时候会过滤两次
第一次是addIncludeFilter
添加的条件
第二次是调用isCandidateComponent(AnnotatedBeanDefinition)
方法
1 | /** |
项目需要实现类似nginx反向代理的功能,于是就采用Filter+HttpClient去实现请求转发。
为了开发方便就采用的springboot做测试项目。
1 | @SpringBootApplication |
Filter里面做匹配Uri后获取request.getInputStream()
用httpClient转发请求
但是在转发Content-Type=multipart/form-data
文件上传时,转发后目标服务器总是获取不到正常的payload的请求体
在Filter里面debug发现压根就获取不到文件…
使用karma+jasmine 构建前端自动化测试环境
在项目下先安装karma 和 jasmine
1 | npm install karma karma-jasmine karma-chrome-launcher --save-dev |
安装karma的命令行
1 | npm install karma-cli -g |
在项目跟路径下初始化karma
1 | karma init |
需要选择初始化的选项,根据自己的需要设置初始化的设置(会生成一个karma.conf.js)
安装karma-coverage 生成代码覆盖率报告
1 | npm install karma-coverage --save-dev |
安装karma-coverage后需要在karma.conf.js 添加相应的配置信息
安装完成后,编写源文件以及相对应的测试文件
开始执行测试(会打开chrome 修改了源文件或测试文件后会自动重新执行测试)
1 | karma start karma.conf.js |
karma.conf.js 具体内容