- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章spring cloud升级到spring boot 2.x/Finchley.RELEASE遇到的坑由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
spring boot2.x已经出来好一阵了,而且spring cloud 的最新release版本finchley.release,默认集成的就是spring boot 2.x,这几天将一个旧项目尝试着从低版本升级到 2.x,踩坑无数,记录一下:
显著变化:
1、gradle的问题 。
spring boot 2.x 要求gradle版本不能太旧,先把gradle升级到4.6版本,然后编译,各种问题,到gradle官网上查了下,build.gradle有几个小地方要调整 。
1.1 java-libary 的项目 。
即:纯工具包这种公用jar,plugins{}必须放在第1行(有buildscript的除外),类似:
1
2
3
4
5
|
plugins {
id
'java-library'
}
|
然后按官网的教程,compile最好换成implementation 。
1
2
3
4
5
|
dependencies {
implementation(
...
)
}
|
1.2 常规java项目(指带容器能独立运行的项目) 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
buildscript {
ext {
springbootversion =
'2.0.1.release'
}
repositories {
maven {
url
"http://maven.aliyun.com/nexus/content/groups/public/"
}
...
}
dependencies {
classpath(
"org.springframework.boot:spring-boot-gradle-plugin:${springbootversion}"
)
}
}
apply plugin:
'java'
apply plugin:
'org.springframework.boot'
apply plugin:
'io.spring.dependency-management'
dependencymanagement {
imports {
mavenbom
'org.springframework.cloud:spring-cloud-dependencies:finchley.release'
}
}<br>...
|
另外,gradle 高版本编译时,总会有一行讨厌的提示:
deprecated gradle features were used in this build, making it incompatible with gradle 5.0. 。
编译时,可以加参数:--warning-mode=none 禁止掉,即类似:
gradle build --warning-mode=none -x test 。
2、依赖jar包版本的问题 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
dependencies {
...
implementation(
...
'org.springframework.cloud:spring-cloud-starter-consul-discovery'
,
'org.springframework.cloud:spring-cloud-starter-consul-config'
,
'org.springframework.cloud:spring-cloud-starter-bus-kafka'
,
'org.springframework.cloud:spring-cloud-starter-sleuth'
,
'org.springframework.cloud:spring-cloud-sleuth-stream:1.3.4.release'
,
'org.springframework.cloud:spring-cloud-starter-hystrix:1.4.4.release'
,
'org.springframework.cloud:spring-cloud-netflix-hystrix-stream'
,
'org.springframework.boot:spring-boot-starter-actuator'
,
'org.springframework.boot:spring-boot-starter-undertow'
,
'org.springframework.boot:spring-boot-starter-mail'
,
'org.springframework.boot:spring-boot-starter-jdbc'
,
'org.springframework.boot:spring-boot-starter-security'
,
'org.slf4j:slf4j-api:1.7.25'
,
'ch.qos.logback:logback-core:1.2.3'
,
'org.thymeleaf:thymeleaf-spring5:3.0.9.release'
,
'org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.1'
,
'tk.mybatis:mapper-spring-boot-starter:1.2.4'
,
'com.github.pagehelper:pagehelper-spring-boot-starter:1.2.3'
)
implementation(
'com.alibaba:druid:1.1.9'
) {
exclude group:
"com.alibaba"
, module:
"jconsole"
exclude group:
"com.alibaba"
, module:
"tools"
}
implementation(
'org.springframework.boot:spring-boot-starter-web'
) {
exclude module:
"spring-boot-starter-tomcat"
exclude module:
"spring-boot-starter-jetty"
}
testcompile
'org.springframework.boot:spring-boot-starter-test'
}
|
其中 。
'org.springframework.cloud:spring-cloud-sleuth-stream:1.3.4.release', 'org.springframework.cloud:spring-cloud-starter-hystrix:1.4.4.release'.
这二项必须指定版本号,否则编译不过。(应该最新的2.x版本的jar包,还没上传到中央仓库,无法自动识别依赖),另外pagehelper这个常用的分页组件,也建议按上面的版本来配置,否则运行时,可能会报错.
3、log4j/log4j2的问题 。
升级到spring boot 2.x后,不管是配置log4j还是log4j2,运行时总是报堆栈溢出的error,换成logback后,启动正常,建议大家尽量采用默认的logback,依赖项的配置参考上面的.
4、datasourcebuilder类找不到的问题 。
spring boot 2.x把这个类换了package,所以找不到了,详情见:
https://stackoverflow.com/questions/50011577/spring-boot-2-0-0-datasourcebuilder-not-found-in-autoconfigure-jar https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/jdbc/datasourcebuilder.html 。
解决办法就是引用:org.springframework.boot:spring-boot-starter-jdbc 。
同时修改代码import新的package: org.springframework.boot.jdbc.datasourcebuilder 。
5、安全性的问题 。
spring boot 2.x加强了安全性,不管访问什么rest url,默认都要求登录,在application.yml里无法通过配置关闭,只能写代码调整:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
import
org.springframework.context.annotation.configuration;
import
org.springframework.security.config.annotation.web.builders.httpsecurity;
import
org.springframework.security.config.annotation.web.configuration.enablewebsecurity;
import
org.springframework.security.config.annotation.web.configuration.websecurityconfigureradapter;
@configuration
@enablewebsecurity
public
class
securityconfiguration
extends
websecurityconfigureradapter {
@override
protected
void
configure(httpsecurity http)
throws
exception {
http.authorizerequests()
.anyrequest()
.permitall()
.and()
.csrf()
.disable();
}
}
|
这样,默认所有url都允许访问(如果是暴露在外网的服务,请慎用) 。
6、各类actuator监控endpoint的路径变化 。
spring boot 2.x 里,actuator的endpoint默认路径变成/actuator开头,如果要使用以前的风格,放在/根下,可以在applicatino.yml里参考下面的配置:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
management:
...
endpoints:
web:
base-path: /
exposure:
include:
"*"
|
另外/health节点,默认情况下,只能输出很少的信息,详细信息,需要通过配置打开 。
1
2
3
4
5
6
7
8
9
10
11
|
management:
...
endpoint:
health:
show-details: always
...
|
7、${spring.cloud.client.ipaddress} 无法识别 。
spring cloud 2.x里,${spring.cloud.client.ipaddress} 这个写法不识别,一启动就会报错,尝试了多次,无意发现,把a改成小写,居然可以了:
1
2
3
4
5
6
7
|
spring:
...
application:
name: sr-menu-service:${spring.cloud.client.ipaddress}
|
感觉这应该是个bug,新版本里估计会修复.
8、metricwriter、systempublicmetrics类找不到的问题 。
spring boot 2.x里metrics默认换成了micrometer,原来的metricwriter之类的全干掉了,详情参考官网文档 。
。
1
2
3
4
5
6
7
8
9
10
11
12
13
|
management:
metrics:
export:
statsd:
host:
10.0
.*.*
port:
8125
flavor: etsy
|
上面的配置是启用statsd,然后跑起来就能看到效果,见下图 。
但是与spring boot 1.x相比,并不会直接输出具体值,要看具体值,可以用http://localhost:8001/metrics/jvm.memory.used 。
这其中的value中是jvm占用的内存(包括heap + noheap),如果只想看heap区(即:堆上的内存),可以用 。
http://localhost:8001/metrics/jvm.memory.used?tag=area:heap 。
同时在grafana里也能看到效果:
注:目前statsd里的前缀无法修改,代码写死的statsd 。
如果一台机器上部署多个spring cloud 微服务,grafana里就分不出来了(个人估计以后会改进).
另外,如果希望通过代码获取这些metrics里具体指标值,可以参考下面的代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
import
io.micrometer.core.instrument.meter;
import
io.micrometer.core.instrument.meterregistry;
import
io.micrometer.core.instrument.statistic;
import
org.junit.test;
import
org.springframework.beans.factory.annotation.autowired;
import
java.util.linkedhashmap;
import
java.util.map;
import
java.util.function.bifunction;
public
class
metricstest
extends
basetest {
private
string metric_msg_format =
"metric >> %s = %d"
;
@autowired
private
meterregistry meterregistry;
@test
public
void
teststatsdconfig() {
string metric =
"jvm.memory.used"
;
meter meter = meterregistry.find(metric).meter();
map<statistic,
double
> stats = getsamples(meter);
logger.info(string.format(metric_msg_format, metric, stats.get(statistic.value).longvalue()));
}
private
map<statistic,
double
> getsamples(meter meter) {
map<statistic,
double
> samples =
new
linkedhashmap<>();
mergemeasurements(samples, meter);
return
samples;
}
private
void
mergemeasurements(map<statistic,
double
> samples, meter meter) {
meter.measure().foreach((measurement) -> samples.merge(measurement.getstatistic(),
measurement.getvalue(), mergefunction(measurement.getstatistic())));
}
private
bifunction<
double
,
double
,
double
> mergefunction(statistic statistic) {
return
statistic.max.equals(statistic) ?
double
::max :
double
::sum;
}
}
|
9、swagger里webmvcconfigureradapter过时的问题 。
webmvcconfigureradapter这个类在最新的spring boot里已经被标识为过时,正常用法参考以下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
import
org.springframework.context.annotation.bean;
import
org.springframework.context.annotation.configuration;
import
org.springframework.web.servlet.config.annotation.resourcehandlerregistry;
import
org.springframework.web.servlet.config.annotation.webmvcconfigurationsupport;
import
springfox.documentation.builders.apiinfobuilder;
import
springfox.documentation.builders.pathselectors;
import
springfox.documentation.builders.requesthandlerselectors;
import
springfox.documentation.service.apiinfo;
import
springfox.documentation.service.contact;
import
springfox.documentation.spi.documentationtype;
import
springfox.documentation.spring.web.plugins.docket;
import
springfox.documentation.swagger2.annotations.enableswagger2;
/**
* @author yangjunming
* @date 13/10/2017
*/
@configuration
@enableswagger2
public
class
swaggerconfig
extends
webmvcconfigurationsupport {
@override
protected
void
addresourcehandlers(resourcehandlerregistry registry) {
registry.addresourcehandler(
"swagger-ui.html"
)
.addresourcelocations(
"classpath:/meta-inf/resources/"
);
registry.addresourcehandler(
"/webjars/**"
)
.addresourcelocations(
"classpath:/meta-inf/resources/webjars/"
);
}
@bean
public
docket createrestapi() {
return
new
docket(documentationtype.swagger_2)
.apiinfo(apiinfo())
.select()
.apis(requesthandlerselectors.basepackage(
"sr.service.menu.controller"
))
.paths(pathselectors.any())
.build();
}
private
apiinfo apiinfo() {
return
new
apiinfobuilder()
.title(
"menu-service online api document"
)
.description(
"测试服务"
)
.contact(
new
contact(
"菩提树下的杨过"
,
"http://yjmyzz.cnblogs.com/"
,
"yjmyzz@126.com"
))
.version(
"1.0.0"
)
.build();
}
}
|
附:一些参考文档:
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Migration-Guide 。
https://spring.io/blog/2017/09/15/security-changes-in-spring-boot-2-0-m4 。
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-Security-2.0 。
https://docs.spring.io/spring-boot/docs/2.0.4.RELEASE/reference/htmlsingle/ 。
https://github.com/pagehelper/pagehelper-spring-boot 。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我.
原文链接:http://www.cnblogs.com/yjmyzz/p/9408700.html 。
最后此篇关于spring cloud升级到spring boot 2.x/Finchley.RELEASE遇到的坑的文章就讲到这里了,如果你想了解更多关于spring cloud升级到spring boot 2.x/Finchley.RELEASE遇到的坑的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我对 c# 有点陌生,我在尝试围绕这个 if-then 语句尝试实现时遇到了一些麻烦。 这是我的目标:当用户将订单输入系统时,将为每个订单创建一个唯一的 orderID。但是,一些附加功能是用户可以选
我已经搜索了这个特定的错误,发现根本问题涉及循环计数错误并导致程序超出数组的界限。 但是,当我将每个数组降低到数组开始丢失输出数据的程度后,它继续抛出相同的错误。我对 C/C++ 仍然是新手,但任何对
我不明白为什么我运行这个小程序时屏幕上没有任何显示? while 循环甚至开始了吗? #include #include int main() { char word[20]; char
我接手了一个用 Perl 编写的项目,它有一些依赖项,例如 Template::Toolkit , Image::ExifTool , 和 GD仅举几例。目前,这些依赖项使用 --prefix 构建到
我想对一个字段进行累积总和,但只要遇到 0 就重置聚合值。 这是我想要的一个例子: data.frame(campaign = letters[1:4] , date=c("jan","
不久前,该项目的 gradle 构建运行良好,但现在一直失败并显示以下错误(带有 --info 标志的输出): Starting process 'Gradle Test Executor 1'. W
我是编程新手,想用 Java 制作一个掷骰子程序来执行。代码如下: import java.math.*; public class Dices { public static int dice1=0
这个问题已经有答案了: What is a StringIndexOutOfBoundsException? How can I fix it? (1 个回答) 已关闭 5 年前。 我对 Java 完
这个方法一直抛出标题中的异常,我找不到原因,我已经通过连接创建了其他表,并且所有引用的表都已创建。我正在使用嵌入式JavaDB . private void createEvidenceTable()
我刚开始上课,这是我第三次尝试上课。我遇到了一个 NameError,我真的不知道如何解决。看看我的程序,看看你能不能帮忙。 import random import math import pyga
好吧,这是我的困境,我向 JFrame 添加了三个面板。第一个(不可见)第二个(可见)和第三个(不可见)..我使用第一个面板作为菜单,当您选择一个选项时,第一个面板被制作(可见),然后第三个面板被制作
我的部分代码遇到问题。如果我选择选项 A,它会运行并给我正确的答案,但是,如果我选择选项 S 或 M,它不会给我任何结果,只会去到它应该去的地方。已经尝试将 if 更改为 else if,但它显示“预
我这里有一些代码,但我正在努力解决它,因为我似乎无法掌握这个文件指针的东西。我对使用文件还很陌生。我见过类似的其他问题,并且尝试了对其他人有效的解决方案,但由于某种原因它们对我不起作用。这是出现问题的
我们有一个很大的应用程序,我们已经将 TODO 规则添加到质量门中,如果发现 TODO 注释,它会给出错误。如果我们只是删除 TODO 注释(这很可怕),它会起作用,但添加 TODO 注释的整个目的就
我正在尝试编写一个名为 isVowel 的函数,它接受一个字符(即长度为 1 的字符串)并在它是元音、大写或小写时返回“true”。如果该字符不是元音字母,该函数应返回“false”。 这看起来应该可
我一直在努力完成我正在做的这个小项目,但由于某种原因它无法正常工作。 问题是当我第一次访问该页面并单击出现在主要部分中的第一个链接时,它会根据需要显示弹出框。现在,当我点击另一天,例如星期天并尝试点击
我正在尝试制作一个 WPF 应用程序。我的窗口内有一个数据网格。我制作了另一个窗口,将新数据添加到我的数据网格中。虽然它按照我想要的方式工作,但我不断遇到异常。我的 MySQL 代码: using S
我试图在我似乎无法使 NSUserDefaults 正常工作的程序中保存几个首选项。如果有人可以查看我的代码并查看是否有任何错误,我们将不胜感激 NSString *kGameIsPaused = @
设置 SymmetricDS版本是3.9.1(也试过3.9.0) 设置是从 postgres 9.5.3 到 postgres 9.5.3 Windows 10 pc(客户端节点)到 Windows
经过长时间的努力,我终于(差不多)完成了我的java菜单程序。但是,我无法让我的返回更改功能在我的代码末尾工作。它给出了非常奇数的数字。有什么想法吗? 代码: import java.io.*; im
我是一名优秀的程序员,十分优秀!