springboot2.0 多數據源整合問題 At least one JPA metamodel must be present! ??at

2019獨角獸企業重金招聘Python工程師標準>>> hot3.png

數據源代碼:

????????? ? 第一個讀取配置文件代碼:

package com.datasource;import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;import javax.sql.DataSource;@Configuration // 注冊到springboot容器中
@MapperScan(basePackages = "com.bdqn.dao", sqlSessionFactoryRef = "test1SqlSessionFactory")
public class TestDatasource01 {/**** @methodDesc: 功能描述:(配置test1數據庫)**/@Bean(name = "test1DataSource")@ConfigurationProperties(prefix = "spring.datasource.test1")// @Primary//自動裝配時當出現多個Bean候選者時,被注解為@Primary的Bean將作為首選者,否則將拋出異常public DataSource testDataSource() {return DataSourceBuilder.create().build();}/**** @methodDesc: 功能描述:(test1 sql會話工廠)*/@Bean(name = "test1SqlSessionFactory")public SqlSessionFactory testSqlSessionFactory(@Qualifier("test1DataSource") DataSource dataSource)throws Exception {SqlSessionFactoryBean bean = new SqlSessionFactoryBean();bean.setDataSource(dataSource);// bean.setMapperLocations(// new// PathMatchingResourcePatternResolver().getResources("classpath:mybatis/mapper/test1/*.xml"));return bean.getObject();}/**** @methodDesc: 功能描述:(test1 事物管理)**/@Bean(name = "test1TransactionManager")public DataSourceTransactionManager testTransactionManager(@Qualifier("test1DataSource") DataSource dataSource) {return new DataSourceTransactionManager(dataSource);}@Bean(name = "test1SqlSessionTemplate")public SqlSessionTemplate testSqlSessionTemplate(@Qualifier("test1SqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {return new SqlSessionTemplate(sqlSessionFactory);}}

? 第二個讀取配置文件代碼:

package com.datasource;import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;import javax.sql.DataSource;@Configuration // 注冊到springboot容器中
@MapperScan(basePackages = "com.bdqn01.dao", sqlSessionFactoryRef = "test2SqlSessionFactory")
public class TestDatasource02 {/**** @methodDesc: 功能描述:(配置test2數據庫)*/@Bean(name = "test2DataSource")@ConfigurationProperties(prefix = "spring.datasource.test2")public DataSource testDataSource() {return DataSourceBuilder.create().build();}/**** @methodDesc: 功能描述:(test2 sql會話工廠)*/@Bean(name = "test2SqlSessionFactory")public SqlSessionFactory testSqlSessionFactory(@Qualifier("test2DataSource") DataSource dataSource)throws Exception {SqlSessionFactoryBean bean = new SqlSessionFactoryBean();bean.setDataSource(dataSource);// bean.setMapperLocations(// new// PathMatchingResourcePatternResolver().getResources("classpath:mybatis/mapper/test2/*.xml"));return bean.getObject();}/**** @methodDesc: 功能描述:(test2 事物管理)*/@Bean(name = "test2TransactionManager")public DataSourceTransactionManager testTransactionManager(@Qualifier("test2DataSource") DataSource dataSource) {return new DataSourceTransactionManager(dataSource);}@Bean(name = "test2SqlSessionTemplate")public SqlSessionTemplate testSqlSessionTemplate(@Qualifier("test2SqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {return new SqlSessionTemplate(sqlSessionFactory);}
}

啟動報錯信息:

????

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: At least one JPA metamodel must be present!at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1702) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:579) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:501) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:741) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]at com.start.main(start.java:11) [classes/:na]
Caused by: java.lang.IllegalArgumentException: At least one JPA metamodel must be present!at org.springframework.util.Assert.notEmpty(Assert.java:450) ~[spring-core-5.0.5.RELEASE.jar:5.0.5.RELEASE]at org.springframework.data.jpa.mapping.JpaMetamodelMappingContext.<init>(JpaMetamodelMappingContext.java:54) ~[spring-data-jpa-2.0.6.RELEASE.jar:2.0.6.RELEASE]at org.springframework.data.jpa.repository.config.JpaMetamodelMappingContextFactoryBean.createInstance(JpaMetamodelMappingContextFactoryBean.java:88) ~[spring-data-jpa-2.0.6.RELEASE.jar:2.0.6.RELEASE]at org.springframework.data.jpa.repository.config.JpaMetamodelMappingContextFactoryBean.createInstance(JpaMetamodelMappingContextFactoryBean.java:43) ~[spring-data-jpa-2.0.6.RELEASE.jar:2.0.6.RELEASE]at org.springframework.beans.factory.config.AbstractFactoryBean.afterPropertiesSet(AbstractFactoryBean.java:141) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1761) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1698) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]... 16 common frames omittedProcess finished with exit code 1

原因沒有指定主數據源

? ? 第一個數據源代碼修改如下

????

package com.datasource;import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;import javax.sql.DataSource;@Configuration // 注冊到springboot容器中
@MapperScan(basePackages = "com.bdqn.dao", sqlSessionFactoryRef = "test1SqlSessionFactory")
public class TestDatasource01 {/**** @methodDesc: 功能描述:(配置test1數據庫)**/@Bean(name = "test1DataSource")@ConfigurationProperties(prefix = "spring.datasource.test1")@Primary//自動裝配時當出現多個Bean候選者時,被注解為@Primary的Bean將作為首選者,否則將拋出異常public DataSource testDataSource() {return DataSourceBuilder.create().build();}/**** @methodDesc: 功能描述:(test1 sql會話工廠)*/@Bean(name = "test1SqlSessionFactory")@Primary//自動裝配時當出現多個Bean候選者時,被注解為@Primary的Bean將作為首選者,否則將拋出異常public SqlSessionFactory testSqlSessionFactory(@Qualifier("test1DataSource") DataSource dataSource)throws Exception {SqlSessionFactoryBean bean = new SqlSessionFactoryBean();bean.setDataSource(dataSource);// bean.setMapperLocations(// new// PathMatchingResourcePatternResolver().getResources("classpath:mybatis/mapper/test1/*.xml"));return bean.getObject();}/**** @methodDesc: 功能描述:(test1 事物管理)**/@Bean(name = "test1TransactionManager")@Primary//自動裝配時當出現多個Bean候選者時,被注解為@Primary的Bean將作為首選者,否則將拋出異常public DataSourceTransactionManager testTransactionManager(@Qualifier("test1DataSource") DataSource dataSource) {return new DataSourceTransactionManager(dataSource);}@Bean(name = "test1SqlSessionTemplate")@Primary//自動裝配時當出現多個Bean候選者時,被注解為@Primary的Bean將作為首選者,否則將拋出異常public SqlSessionTemplate testSqlSessionTemplate(@Qualifier("test1SqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {return new SqlSessionTemplate(sqlSessionFactory);}}

????

轉載于:https://my.oschina.net/u/3535099/blog/3051119

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/251757.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/251757.shtml
英文地址,請注明出處:http://en.pswp.cn/news/251757.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

好書推薦

阿爾花剌子模:代數學. 喬治波利亞:怎樣解題:數學思維的新方法. Anany Levitin:算法設計與分析基礎.轉載于:https://www.cnblogs.com/mtl6906/p/7625290.html

docker實戰系列之搭建rabbitmq

1.搜索鏡像【注&#xff1a;因為我這里采用的是阿里云鏡像加速器,所以我直接在阿里云中搜索相關鏡像路徑】,點擊"詳情"查看公網拉取路徑 2.拉取鏡像 docker pull registry.cn-hangzhou.aliyuncs.com/jc/rabbitmq-3 3.查看拉取的鏡像 docker images 4.創建并運行容器【…

【hdu 6038】Function

【Link】:http://codeforces.com/contest/834/problem/C 【Description】 給你兩個排列a和b; a排列的長度為n,b排列的長度為m; a∈[0..n-1],b∈[0..m-1]; 然后讓你求一個函數f[i]; f[i]的定義域為0..n-1,值域為0..m-1 同時使得對于任意f[i],i∈[0..n-1]; f(i)bf(a[i])成…

樹中點對距離(點分治)

題目 給出一棵帶邊權的樹&#xff0c;問有多少對點的距離<Len 分析 這是一道點分治的經典題目&#xff0c;可以給點分治的初學者練手。 點分治&#xff0c;顧名思義就是把每個點分開了處理答案。 假設&#xff0c;目前做到了以x為根的子樹。 先求出子樹中每個點到根的距離\(…

【a702】貸款利率

Time Limit: 10 second Memory Limit: 2 MB 問題描述 當一個人從銀行貸款后&#xff0c;在一段時間內他將不得不每月嘗還固定的分期付款。這個問題要求計算機出貸款者向銀行支付的利率。假設利率按月累計。 Input 輸入文件 僅一行包含三個用空格隔開的正整數。 第一個整數表示…

移動端適配--meta標簽玩的是什么

基本一直都在做移動端的開發&#xff0c;rem布局也寫了很久&#xff0c;不過對于實現的原理有些模棱兩可的盲點&#xff0c;自己總結一下留著以后回顧。 本文分以下幾個層面&#xff0c;主打用最最通俗的語言來闡述。 布局小例子viewport作用viewport和移動端適配的關系flexibl…

python-json

demjson.encode(self, obj, nest_level0) &#xff1a;用于將 Python 對象編碼成 JSON 字符串。 #!/usr/bin/python import demjsondata [ { a : 1, b : 2, c : 3, d : 4, e : 5 } ]json demjson.encode(data) print json demjson.decode(self, txt) &#xff1a;解碼 JSON 數…

計算機基礎知識--編碼知識

編碼回顧 編碼轉換 Python的bytes類型 編碼回顧 在備編碼相關的課件時&#xff0c;在知乎上看到一段關于Python編碼的回答 這哥們的這段話說的太對了&#xff0c;搞Python不把編碼徹底搞明白&#xff0c;總有一天它會猝不及防坑你一把。 不過感覺這哥們的答案并沒把編碼問題寫明…

Linux——安裝FTP服務器

1、檢查安裝vsftpd軟件 使用如下命令#rpm -qa |grep vsftpd可以檢測出是否安裝了vsftpd軟件&#xff0c; 如果沒有安裝&#xff0c;使用YUM命令進行安裝。 2、啟動服務 使用vsftpd軟件&#xff0c;主要包括如下幾個命令&#xff1a; 啟動ftp命令#service vsftpd start 停止ftp…

測試開發面試準備之Selenium 工作原理

Selenium 經歷了兩個版本&#xff0c;Selenium 1.0 和 Selenium 2.0&#xff0c;本文僅介紹Selenium2的原理&#xff0c;在Selenium 2.0 主推的是WebDriver,Selenium2又名Selenium Webdriver。 Selenium2簡介 Selenium是一個用于Web應用程序測試的工具&#xff0c;支持多平臺、…

CodeForces 11D(狀壓DP 求圖中環的個數)

Given a simple graph, output the number of simple cycles in it. A simple cycle is a cycle with no repeated vertices or edges. Input The first line of input contains two integers n and m (1?≤?n?≤?19, 0?≤?m) – respectively the number of vertices an…

vue插槽的使用(slot)

插槽 該頁面假設你已經閱讀過了組件基礎。如果你還對組件不太了解&#xff0c;推薦你先閱讀它。 插槽內容 Vue 實現了一套內容分發的 API&#xff0c;這套 API 基于當前的 Web Components 規范草案&#xff0c;將 <slot> 元素作為承載分發內容的出口。 它允許你像這樣合成…

圖片與二進制流轉換

#region//圖片轉換為二進制流 public void PictureToBinaryStream() { //獲取當前程序運行路徑 string path Application.StartupPath; //拼接成測試圖片路徑 string fullPath path "\\images\\test.png"; //初始化類 Bitmap bmp…

仿MIUI彈性列表

前言 最近去小米之家體驗了下小米9&#xff0c;發現MIUI有一個挺特別的列表動畫效果&#xff0c;在系統上的各種應用上都能見到它的身影。 網上查了下&#xff0c;小米早在幾個系統版本前就有這個&#xff0c;網上也有了實現這個效果的控件庫。實現方法大同小異&#xff0c;大多…

10、angular的全部api

1、lowercase var app angular.module(myApp, []);app.controller(myCtrl, function($scope) { console.log(angular.lowercase(AbCdEf))}); 2、uppercase var app angular.module(myApp, []);app.controller(myCtrl, function($scope) { console.log(angular.uppercas…

JavaScript快速入門-ECMAScript本地對象(String)

一、String對象 String對象和python中的字符串一樣&#xff0c;也有很多方法&#xff0c;這些方法大概分為以下種類&#xff1a; 1、索引和查找 1、charAt() 返回指定位置的字符。 2、charCodeAt() 返回指定位置的字符的 Unicode 編碼。這個返回值是 0 - 65535 之間的整數。 …

8、angular的select

1、數據源為數組 x for x in names第一個x代表在下拉框內顯示的數據 第二個x指的是在names里數據 <!DOCTYPE html><html><head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0…

ZOJ4116 Game on a Graph

給一個含n個點 m條邊的連通圖 把k個人分成兩組 輪流拿掉一條邊 當取走一條邊后圖不再連通 這個隊就輸了 水題啦 邊為n-1時 下一個拿掉邊的那個組就輸啦 AC代碼&#xff1a; 1 #include<bits/stdc.h>2 using namespace std;3 typedef long long ll;4 typedef unsigned lon…

集美大學1414班軟件工程個人作業2——個人作業2:APP案例分析

一、作業鏈接 個人作業2&#xff1a;APP案例分析 二、博文要求 通過分析你選中的產品&#xff0c;結合閱讀《構建之法》&#xff0c;寫一篇隨筆&#xff0c;包含下述三個環節的所有要求。 第一部分 調研&#xff0c; 評測 下載軟件并使用起來&#xff0c;描述最簡單直觀的個人第…

全局eslint不生效的處理

react項目里能用上 eslint 的 airbnb 規范真是的&#xff0c;對自己的編碼有很好的幫助&#xff0c;不經可以養成良好的代碼風格&#xff0c;而且還能檢測出 state或者變量 是否 使用過&#xff0c; 然而&#xff0c;所在團隊的小伙伴們&#xff0c;卻并未使用&#xff0c;或者…