一、SpringBoot 在整合其资源的时候经常会遇到could not autowired. No beans of ‘xxxx’ type
解决方法:在包DAO中 增加@Component(value = "deptDao")
package com.sky.dao;
import java.util.List;
import com.sky.api.entities.Dept;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Component;
@Mapper
@Component(value = "deptDao")
//SpringBoot 在整合其资源的时候经常会遇到could not autowired. No beans of ‘xxxx’ type
//解决方法:增加@Component(value = "deptDao")
public interface DeptDao
{
public boolean addDept(Dept dept);
public Dept findById(Long id);
public List<Dept> findAll();
}
二、springboot启动报错:Failed to configure a DataSource: 'url' attribute is not specified and no embedded
错误代码:
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
解决方法:
1、在启动类上增加:@EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
2、删除pom文件中有关数据库的依赖
还有:
常规解决方法:
1.由于新建的项目没有配置数据库连接启动报错,可以通过取消自动数据源自动配置来解决
@EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
@SpringBootApplication
2.去配置文件中配置数据库连接参数
3.在springboot 2.0.4版本中(之前用的1.5.4版本没问题,2.0以后好像都有这个问题)application.yml文件中识别不到datasource的配置,这里将application.yml修改为application.properties文件后可以正常解决,但是整个配置文件都要修改,最好的办法还是暂时先不要升级,等后面这个BUG修复后再升级到新版本。
原.yml配置:
spring:
datasource: # 数据库配置
type: com.zaxxer.hikari.util.DriverDataSource
hikari:
# 指定连接数据库的超时时间
login-timeout: 10000
# 指定连接池最大的连接数,包括使用中的和空闲的连接
maximum-pool-size: 30
# 指定必须保持连接的最小值
minimum-idle: 1
jdbc-url: 数据库链接地址
username: 用户名
password: 密码
driver-class-name: oracle.jdbc.driver.OracleDriver
更改为.properties配置文件后
spring.datasource.url=数据库链接地址
spring.datasource.username=用户名
spring.datasource.password=密码
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.datasource.hikari.login-timeout=1000
spring.datasource.hikari.maximum-pool-size=30
三、springboot使用eureka client时,报错:Cannot resolve org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:unknown
不知道什么用原因,以前添加eureka client时凑没有报错,但是今天报错了,哎
pom文件中的版本:
springboot:<version>2.2.5.RELEASE</version>,
cloud:<spring-cloud.version>Hoxton.SR1</spring-cloud.version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.sky.my-springcloud2020</groupId>
<artifactId>my-springcloud2020</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.SR1</spring-cloud.version>
</properties>
以前都是这样,也没报错,但是昨晚新加的eureka client 就报错,
解决方法:添加eureka client 的版本号:
<!-- 将微服务provider侧注册进eureka -->
<!-- 不知道为什么得加版本号version,原来都不要的!!-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>
四、springboot + gateway项目启动时报错:(是父子工程,gateway是一个子module)
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of method modifyRequestBodyGatewayFilterFactory in org.springframework.cloud.gateway.config.GatewayAutoConfiguration required a bean of type 'org.springframework.http.codec.ServerCodecConfigurer' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.http.codec.ServerCodecConfigurer' in your configuration.
Process finished with exit code 0
后经查找资料解决,此处做记录:
原因:
依赖冲突,spring-cloud-starter-gateway与spring-boot-starter-web和spring-boot-starter-webflux依赖冲突
解决:
排除 spring-boot-starter-web和spring-boot-starter-webflux依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</exclusion>
</exclusions>
</dependency>
注:排除 spring-boot-starter-web和spring-boot-starter-webflux依赖,gateway项目可以启动,但是功能可能丢失
spring-boot-starter-webflux不排除,排除后启动时会有报错提示:
**********************************************************
Spring Webflux is missing from the classpath, which is required for Spring Cloud Gateway at this time. Please add spring-boot-starter-webflux dependency.
**********************************************************
2020-04-11 10:49:39.939 WARN 9188 --- [ restartedMain] GatewayClassPathWarningAutoConfiguration :
**********************************************************
Spring MVC found on classpath, which is incompatible with Spring Cloud Gateway at this time. Please remove spring-boot-starter-web dependency.
**********************************************************
所以我能想到的办法就是:gateway单独一个工程(不需要导入spring-boot-starter-web),这样启动完全没有问题。
五、