欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

springboot 如何取消starter的自動(dòng)注入

 更新時(shí)間:2021年09月10日 16:50:18   作者:qq_29914229  
這篇文章主要介紹了springboot 如何取消starter的自動(dòng)注入操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

springboot 取消starter的自動(dòng)注入

starer是spring boot中一個(gè)很重要的概念,starter相當(dāng)于一個(gè)模塊,它能將所需要的的依賴整合在一起并對(duì)模塊內(nèi)的bean自動(dòng)裝配到spring IOC容器,使用者只需要在maven中依賴相應(yīng)的starter包并無需做過多的依賴即可進(jìn)行開發(fā)。

看例子

比如,我們導(dǎo)入了mybatis相關(guān)的依賴,但是我可能暫時(shí)沒用到數(shù)據(jù)庫,所以就沒有做數(shù)據(jù)庫相關(guān)的配置,這時(shí)候項(xiàng)目就會(huì)無法啟動(dòng)

2020-03-08 22:13:10.396 WARN 10692 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt:

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

因?yàn)閟pringboot中默認(rèn)的數(shù)據(jù)庫連接池是hikari,你沒有在application.properties里面進(jìn)行數(shù)據(jù)庫相關(guān)的配置的話,那么就會(huì)無法自動(dòng)裝載dataSource

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]

重點(diǎn)來了

如何取消相關(guān)starer的自動(dòng)注入?

我們還是以數(shù)據(jù)庫的這個(gè)為例子:

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)

那么,就需要在啟動(dòng)類加上如上配置,取消DataSourceAutoConfiguration的自動(dòng)注入

springbootApplication是一個(gè)組合注解,其實(shí)里面真正實(shí)現(xiàn)自動(dòng)注入功能的,是這個(gè)EnableAutoConfiguration注解

SpringBoot 自動(dòng)注入問題

Description:

Field service in com.test.controller.UserController required a bean of type 'com.test.service.UserService' that could not be found.

Action:

Consider defining a bean of type 'com.test.service.UserService' in your configuration.

項(xiàng)目啟動(dòng)的時(shí)候出現(xiàn)出現(xiàn)問題

run

controller

service

dao

配置文件如下

項(xiàng)目目錄

找了幾個(gè)類,該注解的也注解了。

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • java讀取word-excel-ppt文件代碼

    java讀取word-excel-ppt文件代碼

    OFFICE文檔使用POI控件,PDF可以使用PDFBOX0.7.3控件,完全支持中文,用XPDF也行,不過感覺PDFBOX比較好,而且作者也在更新。水平有限,萬望各位指正
    2009-04-04
  • spring boot整合scurity做簡(jiǎn)單的登錄校驗(yàn)的實(shí)現(xiàn)

    spring boot整合scurity做簡(jiǎn)單的登錄校驗(yàn)的實(shí)現(xiàn)

    這篇文章主要介紹了spring boot整合scurity做簡(jiǎn)單的登錄校驗(yàn)的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-04-04
  • java實(shí)現(xiàn)俄羅斯方塊游戲

    java實(shí)現(xiàn)俄羅斯方塊游戲

    這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)俄羅斯方塊游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-02-02
  • JVM調(diào)優(yōu)參數(shù)的設(shè)置

    JVM調(diào)優(yōu)參數(shù)的設(shè)置

    Java虛擬機(jī)的調(diào)優(yōu)是一個(gè)復(fù)雜而關(guān)鍵的任務(wù),可以通過多種參數(shù)來實(shí)現(xiàn),本文就來介紹一下JVM調(diào)優(yōu)參數(shù)的設(shè)置,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-03-03
  • SpringSecurity?表單登錄的實(shí)現(xiàn)

    SpringSecurity?表單登錄的實(shí)現(xiàn)

    本文主要介紹了SpringSecurity?表單登錄的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-12-12
  • Mybatis插入數(shù)據(jù)后自增id獲取方式

    Mybatis插入數(shù)據(jù)后自增id獲取方式

    在MyBatis中,獲取自增主鍵可以通過useGeneratedKeys屬性或selectKey節(jié)點(diǎn)實(shí)現(xiàn),useGeneratedKeys設(shè)置時(shí),需設(shè)置keyProperty指定主鍵字段,數(shù)據(jù)庫表也要相應(yīng)設(shè)置,selectKey節(jié)點(diǎn)可在插入操作后,通過特定SQL查詢獲得主鍵
    2024-09-09
  • 圖書管理系統(tǒng)java版

    圖書管理系統(tǒng)java版

    這篇文章主要為大家詳細(xì)介紹了java版的圖書管理系統(tǒng),通過實(shí)例為大家快速掌握數(shù)據(jù)庫編程技術(shù),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-06-06
  • rocketmq的AclClientRPCHook權(quán)限控制使用技巧示例詳解

    rocketmq的AclClientRPCHook權(quán)限控制使用技巧示例詳解

    這篇文章主要為大家介紹了rocketmq的AclClientRPCHook使用技巧示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-08-08
  • Java實(shí)現(xiàn)Twitter的分布式自增ID算法snowflake

    Java實(shí)現(xiàn)Twitter的分布式自增ID算法snowflake

    這篇文章主要介紹了Java實(shí)現(xiàn)Twitter的分布式自增ID算法snowflake,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-08-08
  • Apache Commons fileUpload實(shí)現(xiàn)文件上傳之一

    Apache Commons fileUpload實(shí)現(xiàn)文件上傳之一

    這篇文章主要介紹了Apache Commons fileUpload實(shí)現(xiàn)文件上傳之一的相關(guān)資料,需要的朋友可以參考下
    2016-03-03

最新評(píng)論