0%

Spring系列之SpringBoot

TodoItem

如果配置文件不再Application启动器的同目录或者子目录下,就需要采用@Import引入? todo

有没有自动生成banner的工具? todo

@SpringBootConfiguration和@SpringBootApplication区别 todo

bootstrap.yml非默认的情况下怎样才能被application.yml覆盖?todo

Basic Knowledge

采用SpringBoot处理国际化问题

Guide to Internationalization in Spring Boot

SpringBoot基础教程

spring-boot-configuration-processor

可以更加优雅地读取配置文件的值,参考https://blog.csdn.net/fzbbw/article/details/101175595

远程Debug(Remote Debug)

https://blog.csdn.net/weixin_42740530/article/details/89524509

Problem Solution

required a bean of type ‘javax.sql.DataSource’ that could not be found.

需要手动配置spring-boot-starter-jdbc的依赖jar

Consider revisiting the entries above or defining a bean of type ‘org.springframework.security.core.userdetails.UserDetailsService’ in your configuration.

需要自己实现UserDetailsService,并注入到Spring。

2019-12-19 14:24:44.064 WARN 2849 — [ XNIO-1 task-7] com.zaxxer.hikari.pool.PoolBase : HikariPool-1 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@6bee636d (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.

使用hikari需要配置加上max-lifetime: 27700000,如:

1
2
3
4
5
6
7
8
9
10
# 数据源
spring:
datasource:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: raubbhWy
url: jdbc:mysql://39.100.106.97:3306/inspect_db?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
hikari:
max-lifetime: 27700000

Caused by: java.lang.ClassNotFoundException: org.springframework.cloud.context.named.NamedContextFactory$Specification

原因:OpcApplication 中有注解@EnableFeignClients,但是在控制器或对外实现接口中,SpringBoot没有扫描到@FeignClient注解的程序

解决:要么给程序加注解@FeignClient,要么把 OpcApplication 中有注解@EnableFeignClients 暂时去掉

还有网上提到需要增加对应的依赖:

1
2
3
4
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-context</artifactId>
</dependency>