springboot项目集成swagger的实现
这几日在项目中,老是看到看到许多swagger注解,许多只能了解各大概,抱着得过且过的态度用用就行了。直到自己在构建项目时,发现单纯的添加依赖会报空指针错误。
Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException
一番百度后发现,Springfox假设MVC的路径匹配政策是ant-path-matcher,而 Spring Boot 2.6.x版本的默认匹配策略是 path-pattern-matcher,这就造成了上面的报错。
依赖<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-boot-starter</artifactId> <version>3.0.0</version></dependency>
配置注解@C ...
通过Feign调用外网HTTP,设置请求头,熔断器
在许多项目中,往往需要和其他厂商的项目进行对接。这就不得不访问外部url接口。网上的各种方案层出不穷,但我不太喜欢额外添加maven依赖,所以使用已有的feign实现。
由于个人习惯,我的spring-boot版本是2.6.7。这导致了我添加openfeign依赖时总是报错,因为网络上的教程往往是使用了Hoxton.SR8版本的spring-cloud,它的绑定依赖openfeign是2.2.5.RELEASE。
版本兼容的问题往往最难为新手。
添加Maven依赖
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId><version>3.1.1</version></dependency><dependency> <groupId>org.springframework.cloud</gr ...
Copy 'xxx' to effectively final temp variable 问题解决
今天在项目中修改接口的时候突然发现了类型问题,便用if函数对变量进行了类型的校验。
int a = 0;if (params.get("a") instanceof Integer) { a = (int) params.get("a");}else { a = Integer.parseInt(params.get("a").toString());}
没有多想,便进行了提交,编译后发现竟然报错了。筛查后发现,在这块代码下有一处匿名内部类调用了该变量。
int finalA = a;Thread thread = new Thread(new Runnable() { @Override public void run() { System.out.println("thread a = " + finalA); }});
出错的原因是:内部类对象的生命周期会超过局部变量的生命周期。 ...
Hello World
Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.
Quick StartCreate a new post$ hexo new "My New Post"
More info: Writing
Run server$ hexo server
More info: Server
Generate static files$ hexo generate
More info: Generating
Deploy to remote sites$ hexo deploy
More info: Deployment