国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

在springboot項(xiàng)目中配置數(shù)據(jù)庫(kù)下劃線命名映射為java的駝峰命名時(shí)出錯(cuò)

這篇具有很好參考價(jià)值的文章主要介紹了在springboot項(xiàng)目中配置數(shù)據(jù)庫(kù)下劃線命名映射為java的駝峰命名時(shí)出錯(cuò)。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

問(wèn)題

在使用spirngboot集成mybaits的時(shí)候,想要開(kāi)啟命名映射,如圖配置

# mybatis配置
mybatis:
  type-aliases-package: com.zhong.springcloud.pojo
  config-location: classpath:mybatis/mybatis-config.xml
  mapper-locations: classpath:mybatis/mapper/*.xml
#  命名映射
  configuration:
    map-underscore-to-camel-case: true

項(xiàng)目中配置了mybatis-config.xml
在springboot項(xiàng)目中配置數(shù)據(jù)庫(kù)下劃線命名映射為java的駝峰命名時(shí)出錯(cuò)
mybatis-config.xml文件中的配置

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">

<configuration>
    <settings>
        <!--        開(kāi)啟二級(jí)緩存-->
        <setting name="cacheEnabled" value="true"/>
    </settings>
</configuration>

錯(cuò)誤信息

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method ‘sqlSessionFactory’ threw exception; nested exception is java.lang.IllegalStateException: Property ‘configuration’ and ‘configLocation’ can not specified with together
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.24.jar:5.3.24]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.24.jar:5.3.24]
… 78 common frames omitted
Caused by: java.lang.IllegalStateException: Property ‘configuration’ and ‘configLocation’ can not specified with together
at org.springframework.util.Assert.state(Assert.java:76) ~[spring-core-5.3.24.jar:5.3.24]
at org.mybatis.spring.SqlSessionFactoryBean.afterPropertiesSet(SqlSessionFactoryBean.java:488) ~[mybatis-spring-2.0.7.jar:2.0.7]
at org.mybatis.spring.SqlSessionFactoryBean.getObject(SqlSessionFactoryBean.java:633) ~[mybatis-spring-2.0.7.jar:2.0.7]
at org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration.sqlSessionFactory(MybatisAutoConfiguration.java:188) ~[mybatis-spring-boot-autoconfigure-2.2.2.jar:2.2.2]
at org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration E n h a n c e r B y S p r i n g C G L I B EnhancerBySpringCGLIB EnhancerBySpringCGLIB36ad62da.CGLIB$sqlSessionFactory 1 ( < g e n e r a t e d > ) ? [ m y b a t i s ? s p r i n g ? b o o t ? a u t o c o n f i g u r e ? 2.2.2. j a r : 2.2.2 ] a t o r g . m y b a t i s . s p r i n g . b o o t . a u t o c o n f i g u r e . M y b a t i s A u t o C o n f i g u r a t i o n 1(<generated>) ~[mybatis-spring-boot-autoconfigure-2.2.2.jar:2.2.2] at org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration 1(<generated>)?[mybatis?spring?boot?autoconfigure?2.2.2.jar:2.2.2]atorg.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration E n h a n c e r B y S p r i n g C G L I B EnhancerBySpringCGLIB EnhancerBySpringCGLIB 36 a d 62 d a 36ad62da 36ad62da F a s t C l a s s B y S p r i n g C G L I B FastClassBySpringCGLIB FastClassBySpringCGLIB 54783 d 2 d . i n v o k e ( < g e n e r a t e d > ) ? [ m y b a t i s ? s p r i n g ? b o o t ? a u t o c o n f i g u r e ? 2.2.2. j a r : 2.2.2 ] a t o r g . s p r i n g f r a m e w o r k . c g l i b . p r o x y . M e t h o d P r o x y . i n v o k e S u p e r ( M e t h o d P r o x y . j a v a : 244 ) ? [ s p r i n g ? c o r e ? 5.3.24. j a r : 5.3.24 ] a t o r g . s p r i n g f r a m e w o r k . c o n t e x t . a n n o t a t i o n . C o n f i g u r a t i o n C l a s s E n h a n c e r 54783d2d.invoke(<generated>) ~[mybatis-spring-boot-autoconfigure-2.2.2.jar:2.2.2] at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.3.24.jar:5.3.24] at org.springframework.context.annotation.ConfigurationClassEnhancer 54783d2d.invoke(<generated>)?[mybatis?spring?boot?autoconfigure?2.2.2.jar:2.2.2]atorg.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)?[spring?core?5.3.24.jar:5.3.24]atorg.springframework.context.annotation.ConfigurationClassEnhancerBeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) ~[spring-context-5.3.24.jar:5.3.24]
at org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration E n h a n c e r B y S p r i n g C G L I B EnhancerBySpringCGLIB EnhancerBySpringCGLIB36ad62da.sqlSessionFactory() ~[mybatis-spring-boot-autoconfigure-2.2.2.jar:2.2.2]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_271]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_271]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_271]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_271]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.24.jar:5.3.24]
… 79 common frames omitted

關(guān)閉命名映射之后或者關(guān)閉配置路徑之后項(xiàng)目正常。

原因分析

根據(jù)錯(cuò)誤信息分析,出現(xiàn)該錯(cuò)誤的原因是同時(shí)使用了configLocation和configuration屬性。這兩個(gè)屬性是SqlSessionFactoryBean類的屬性,分別用于指定MyBatis配置文件的位置和MyBatis配置對(duì)象。

在配置中,你在application.xml中指定了configLocation屬性,在mybatis-config.xml中定義了MyBatis的配置對(duì)象,在applicaiton中又指定了configuration屬性,因此出現(xiàn)了沖突。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-440014.html

解決方法

  1. 解決該問(wèn)題的方法是,需要在應(yīng)用程序中刪除configLocation屬性,只使用applicaiton.yml中的configuration屬性來(lái)指定MyBatis的配置對(duì)象。或者不使用applicaiton.yml中的configuration屬性,就可以配置config-locations并且在其中配置屬性
  2. 如果需要同時(shí)啟用這兩個(gè)屬性,則需要自定義一個(gè)MybatisConfig類,該類將擴(kuò)展org.mybatis.spring.boot.autoconfigure.MybatisProperties類。

到了這里,關(guān)于在springboot項(xiàng)目中配置數(shù)據(jù)庫(kù)下劃線命名映射為java的駝峰命名時(shí)出錯(cuò)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • SpringBoot項(xiàng)目配置文件數(shù)據(jù)庫(kù)用戶名密碼加密

    SpringBoot項(xiàng)目配置文件數(shù)據(jù)庫(kù)用戶名密碼加密

    在使用SpringBoot開(kāi)發(fā)過(guò)程中,會(huì)將一些敏感信息配置到SpringBoot項(xiàng)目的配置文件中( 不考慮使用配置中心的情況 ),例如數(shù)據(jù)庫(kù)的用戶名和密碼、Redis的密碼等。為了保證敏感信息的安全,我們需要將此類數(shù)據(jù)進(jìn)行加密配置。 目前通用的做法是使用 jasypt 對(duì)數(shù)據(jù)庫(kù)用戶名或者密碼

    2024年02月10日
    瀏覽(28)
  • SpringBoot系列之Web如何支持下劃線駝峰互轉(zhuǎn)的傳參與返回

    SpringBoot系列之Web如何支持下劃線駝峰互轉(zhuǎn)的傳參與返回

    SpringBoot系列之Web如何支持下劃線駝峰互轉(zhuǎn)的傳參與返回 接下來(lái)介紹一個(gè)非常現(xiàn)實(shí)的應(yīng)用場(chǎng)景,有些時(shí)候后端接口對(duì)外定義的傳參/返回都是下劃線命名風(fēng)格,但是Java本身是推薦駝峰命名方式的,那么必然就存在一個(gè)傳參下?lián)Q線,轉(zhuǎn)換成駝峰的場(chǎng)景;以及在返回時(shí),將駝峰命名

    2024年02月22日
    瀏覽(18)
  • SpringBoot項(xiàng)目application配置文件數(shù)據(jù)庫(kù)密碼上傳git暴露問(wèn)題解決方案

    SpringBoot項(xiàng)目application配置文件數(shù)據(jù)庫(kù)密碼上傳git暴露問(wèn)題解決方案

    項(xiàng)目中含有配置文件,配置文件中含有數(shù)據(jù)庫(kù)的用戶名和密碼,上傳git直接對(duì)外網(wǎng)開(kāi)放。那后果會(huì)怎樣可想而知。 jasypt(Java Simplified Encryption)是一個(gè)簡(jiǎn)化的開(kāi)源 Java 加密工具庫(kù) 輸出 使用很簡(jiǎn)單,只需要引入jasypt-spring-boot-starter依賴,然后將配置文件中的明文換成\\\"ENC(密文即可)“

    2024年04月14日
    瀏覽(27)
  • word@制表位和列數(shù)據(jù)對(duì)齊@填空下劃線制作

    word@制表位和列數(shù)據(jù)對(duì)齊@填空下劃線制作

    Insert or add tab stops - Microsoft Support Using the ruler in Word - Microsoft Support 在Microsoft Word中,制表符(Tab)是一種用于控制文本對(duì)齊和縮進(jìn)的功能。制表符可以幫助您在文檔中創(chuàng)建整齊的布局,如制作目錄、制作表格或?qū)R文本等。 制表位類型 Word中有四種主要的制表符: 左對(duì)齊制表

    2024年02月13日
    瀏覽(16)
  • Python 中的單下劃線和雙下劃線

    哈嘍大家好,我是咸魚(yú) 當(dāng)我們?cè)趯W(xué)習(xí) Python 的時(shí)候,可能會(huì)經(jīng)常遇到單下劃線 _ 和雙下劃線 __ 這兩種命名方式 單下劃線 _ 和雙下劃線 __ 不僅僅是只是一種簡(jiǎn)單的命名習(xí)慣,它們?cè)?Python 中有著特殊的含義,對(duì)于代碼的可讀性和功能實(shí)現(xiàn)有著關(guān)鍵的作用。 那么今天我們來(lái)看一

    2024年02月05日
    瀏覽(23)
  • 詳解Python單下劃線和雙下劃線使用

    在Python編程中,我們經(jīng)常會(huì)遇到單下劃線(_)和雙下劃線(__)的使用。它們?cè)诿麡?biāo)識(shí)符、變量、方法和屬性中扮演著不同的角色。本文將詳細(xì)解釋Python中單下劃線和雙下劃線的含義和用法,并通過(guò)代碼示例進(jìn)行講解,幫助你理解它們的作用和適用場(chǎng)景。 命名約定。在Py

    2024年02月10日
    瀏覽(20)
  • HTML中設(shè)定下劃線樣式并且指定下劃線長(zhǎng)度

    HTML中設(shè)定下劃線樣式并且指定下劃線長(zhǎng)度

    今天筆者在寫(xiě)網(wǎng)頁(yè)導(dǎo)航欄時(shí),想要給鏈接加一個(gè)懸停下劃線,寫(xiě)出來(lái)如下 HTMl: CSS:(關(guān)于其他格式的設(shè)定略,只看下劃線這一段代碼) 這樣確實(shí)是設(shè)定下劃線了,但是效果如下,看上去很難看 既然這樣,那么該如何改變一下呢? 其實(shí)可以使用border-bottom來(lái)實(shí)現(xiàn),代碼如下

    2024年02月10日
    瀏覽(19)
  • SpringBoot項(xiàng)目連接數(shù)據(jù)庫(kù)

    SpringBoot項(xiàng)目連接數(shù)據(jù)庫(kù)

    1、找到applications.yml,如下圖 ?2、寫(xiě)入代碼 ?

    2024年02月15日
    瀏覽(23)
  • SpringBoot如何配置數(shù)據(jù)庫(kù)

    項(xiàng)目啟動(dòng)需要一個(gè)鏈接數(shù)據(jù)庫(kù),所以在此記錄一下。 根據(jù)配置文件的后綴書(shū)寫(xiě)格式略有不同。 此處以MySQL為例,使用Maven為例 若是.yaml后綴的配置文件,那么端口書(shū)寫(xiě)為 解釋: ①導(dǎo)入數(shù)據(jù)源和JDBC驅(qū)動(dòng) 的依賴包 ②配置文件中配置數(shù)據(jù)庫(kù) ③開(kāi)始使用

    2024年02月11日
    瀏覽(18)
  • css 下劃線

    在 CSS 中,可以使用 \\\"text-decoration\\\" 屬性來(lái)設(shè)置文本的下劃線。例如: 這會(huì)使所有的段落文本都帶有下劃線。你也可以使用 \\\"text-decoration-style\\\" 屬性來(lái)設(shè)置下劃線的樣式,例如實(shí)線、虛線或點(diǎn)線等。 你還可以使用 \\\"border-bottom\\\" 屬性來(lái)設(shè)置下劃線,例如: 這會(huì)在段落文本下方添加

    2024年02月12日
    瀏覽(20)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包