学习SpringBoot时遇到的一些问题排查

1. 错误页面:This application has no explicit mapping for /error, so you are seeing this as a fallback.

Application程序应该在最外层的包,包含所有子包,Spring boot会自动加载启动类所在包下及其子包下的所有组件

2.Not registered via @EnableConfigurationProperties, marked as Spring component, or scanned via @ConfigurationPropertiesScan

使用@ConfigurationProperties 将bean属性和配置文件绑定时出现此报错

1.在pom中添加依赖:配置文件处理器,配置文件进行绑定就会有提示

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-configuration-processor</artifactId>
    <optional>true</optional>
</dependency>

2.只有这个组件是容器中的组件,才能使用容器提供的功能;

添加@Component 注解加入容器

3.properties配置文件中文乱码问题

IDEA默认使用的是utf-8,在IDEA设置的File Encodings项里选择properties Files的编码为utf-8,并且将transparent native-to-ascii conversion的选项勾上,可以在运行时将properties文件的编码转为ascii码

4.静态资源引发的错误

有可能是因为浏览器缓存才导致达不到预期效果,注意排查,清空缓存重新加载

5.发送去请求跳转页面时需要注意

请求的方法控制器上不要有@ResController或者该方法上不要注解@ResponseBody

6.使用JDBC连接数据库出现The server time zone value '�й���׼ʱ��' is解决方案

url后加入?serverTimezone=UTC即可解决

高版本的 spring boot 搭配 mysql 驱动版本较高时,如 mysql-connector-java:8.0.16,此时 driver-class-name 的值要带 cj;url 的值要带时区 serverTimezone

7. The elements [spring.datasource.schema[0].classpath,spring.datasource.schema[1].classpath] were left unbound.

创建表获取执行语句时报错,编写yml的时候多写了一个空格

错误:
schema:
  - classpath: schema-all.sql
  - classpath: employee.sql
    
正确:
schema:
  - classpath:schema-all.sql
  - classpath:employee.sql
    

8.nested exception is org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException: Property spring.datasource.schema with value 'class path resource [employee.sql]' is invalid: The specified resource does not exist.

springboot2.x 执行sql文件时出现的错,配置文件增加initialization-mode: always

    initialization-mode: always
    schema:
     - classpath:schema-all.sql
     - classpath:employee.sql

9. 自定义druidDataSource出现的错误

两种解决方法:

  1. 导入log4j依赖就可以
  2. 在filter中去掉log4j

猜你喜欢

转载自www.cnblogs.com/JIATCODE/p/13202710.html