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.mzph.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;或者…