Bug集锦

1、Java出现The server time zone value ‘�й���׼ʱ��’ is unrecogni的解决

https://blog.csdn.net/bfelfish/article/details/90146541

2、数据源信息未配置

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class

需求:根据配置文件,切换不同数据源
方案:在application.properties文件中配置多数据源,并在java包下创建configuration,在test中测试
问题:由于test中没有加载到java中的configuration文件,且没有配置默认的spring.dataSource参数,故初始化dataSource时报错
解决:在test文件中添加@Configuration(java包下的类)

3、默认加载多数据源,初始化时系统无法选择

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'db1DataSource' defined in class path resource [com/example/JdbcDemo/JdbcDataSourceConfig.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker': Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.springframework.boot.autoconfigure.jdbc.DataSourceProperties' available: expected single matching bean but found 3: db1DataSourceProperties,db2DataSourceProperties,spring.datasource-org.springframework.boot.autoconfigure.jdbc.DataSourceProperties

需求:多数据源配置
方案:在application.properties文件中配置多数据源,并在java包下创建configuration,在test中测试
问题:context初始化时,会加载所有标志了bean的类,当注入dataSource时,系统发现有多个默认实现,无法选择
解决:①、在自定义的数据源上选择一个默认的@Primary
②、排除掉系统默认加载@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class})

4、新建项目SpringBootApplication无法引入的问题

解决方法一:

检查新项目的 pom.xml 中定义的 version 是否和旧项目不同。改成和旧项目保持一致之后,刷新项目,可解决问题。

 <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.3.RELEASE</version>
    </parent>

解决方法二:
是springboot的包冲突了所致。需要删掉 repository\org\springframework\boot 目录下的spring-boot-autoconfigure 文件夹即可,然后在工程中maven -> update project即可

注:个人倾向第一种,第二种虽然获取最新版本,但不稳定,或许出现更多问题,例如下面这个问题。

5、运行具体某一个包含main() 方法的类时候出现java.lang. NoClassDefFoundError:

分析:根据上面的相关信息,基本上可以判断该问题是找不对相关类,即找不到 ListableBeanFactory 类。ListableBeanFactory 类位于 spring-bean 中的jar包。在一些低版本的 spring 框架中,可能不存在该jar包,升级相关jar包即可。
解决方案:另外我发现在 spring-boot 的1.5.9 版本中会报该错误。而使用 spring-boot-starter-parent1.5.8.RELEASE 启动则无任何问题。遇到该问题可以在相关jar包中查看是否有这个类,如果没有则升级 jar 包。或者降级相应的 jar 文件。
即:找到稳定版本使用即可

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值