Java Springcloud项目bug记录过程01

1.Failed to configure a DataSource

springcloud项目启动时,启动报错:Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

 分析:application.yml文件中已经配置了数据库

  datasource:
      url: jdbc:mysql://localhost:3306/day1?serverTimezone=UTC&useSSL=false
      username: root
      password: ******
      driver-class-name: com.mysql.cj.jdbc.Driver

解决方案:通过分析发现,application.yml文件idea并未识别,进行手动添加。

此时,项目的application.yml文件被识别。

2.IDEA run或debug 点击无反应?

然后尝试点击toolbar 上的run 按钮,run变成灰色了。。。

点击debug 按钮,debug变成灰色了。。。

再试一下后边的按钮。。。

原因:kotlin依赖冲突

我是添加了OkHttp3,但是发现里面也是添加了kotlin包,我的idea也是2018.1版本,,,,,然后我是将kotlin排除了,然后就可以了

        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib-common</artifactId>
            <version>1.3.41</version>
        </dependency> 

3.springboot项目中提示报错Cannot resolve configuration property 'spring.datasource.xxxx' 和hikari配置属性

druid和druid-spring-boot-starter区别分析:

(1)作用是一样的,都是连接池提供连接,里边的配置参数都是一样的;

(2)druid-spring-boot-starter只是在druid基础上进行了一次封装,专门用来整合spring-boot项目
如果springboot项目想使用druid也是可以的,但是需要手动编写配置类并注入到bean中,并加载对应的配置参数;但是不建议,明明有现成封装好的jar,就直接使用就好了!!!

出现如下报错:

 原因是没有导入druid-spring-boot-starter依赖。

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
        </dependency>    

总结:

①springboot项目整合druid,建议使用druid-spring-boot-strater,但是不代表druid一定不可以使用,有兴趣的可以自己试试
②配置yaml文件时,一定要使用druid下边的参数,要不然不起作用

 4.mybatis-plus某个包没有被扫描进来,报错

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'bsClientSubsysServiceImpl': Unsatisfied dependency expressed through field 'baseMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.ttbank.flep.admin.mapper.BsClientSubsysMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:596)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90)
   
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.ttbank.flep.admin.mapper.BsClientSubsysMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1658)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1217
    ... 19 common frames omitted

解决方案:添加扫描

@MapperScan("com.ttbank.flep.admin.mapper") 

5.‘org.jeecg.common.api.CommonAPI' not be found 错误解决办法

模块中引入其他依赖,需要使用feign功能

***************************
APPLICATION FAILED TO START
***************************

Description:

Field commonAPI in org.jeecg.common.aspect.DictAspect required a bean of type 'org.jeecg.common.api.CommonAPI' that could not be found.

The injection point has the following annotations:
    - @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean of type 'org.jeecg.common.api.CommonAPI' in your configuration.

bug原因分析:

由于jeecg-boot创建的cloud项目中引入了

    <dependencies>
        <dependency>
            <groupId>org.jeecgframework.boot</groupId>
            <artifactId>jeecg-boot-base-core</artifactId>
        </dependency>
        <!--引入微服务启动依赖 starter-->
        <dependency>
            <groupId>org.jeecgframework.boot</groupId>
            <artifactId>jeecg-boot-starter-cloud</artifactId>
        </dependency>

    </dependencies>

微服务启动依赖jeecg-boot-starter-cloud使用的feign,

解决方案:在FlepAdminApplication添加注解@EnableFeignClients(basePackages = "org.jeecg")

 

参考文献:

https://zhuanlan.zhihu.com/p/75231714

posted @ 2021-08-17 20:17  雨后观山色  阅读(469)  评论(0编辑  收藏  举报