1、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();
}
2、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).
解決方法:在啓動類上增加:@EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
還有:
常規解決方法:
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