问题一:父模块中指定了版本,但是子模块却没有读取到。
在子模块中指定 parent
,这里我父模块是 叫 test-demo
<parent>
<groupId>com.yichen</groupId>
<artifactId>test-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
** 注意,这样指定 parent
后,spring-boot
的版本号便会根据 父模块中指定的 spring-boot
版本号,这样可能会与 子模块中 的 spring-cloud
产生冲突
错误内容如下
The bean 'dataSource', defined in BeanDefinition defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class] and overriding is disabled.
这个问题百度了一下,好多只说了解决方法,通过该错误附带的提示即可解决
在 配置文件中添加 spring.main.allow-bean-definition-overriding=true
即可。但是产生错误的原因基本都没找,后面排查了一下问题,发现是 spring-boot
版本 和 spring-cloud
版本不一致,因为我一开始 spring-boot
的版本不是现在父模块中指定的版本号。
这里给出后面我修改后的对应版本号。
// 父模块中
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
// 子模块中
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>2.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
<version>2.2.4.RELEASE</version>
</dependency>
运行程序报错
The server time zone value ‘йʱ’ is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
解决参考1
解决参考2
都说了需要在url中添加 serverTimeZone
,但是 serverTimezone=Asia/Hongkong
行不通,serverTimezone=UTC%2b8
也行不通,查了一下 /usr/share/zoneinfo
(我用的是window的WSL),内容如下
里面有个Hongkong
,试了一下 serverTimezone=Hongkong
成功。