您现在的位置是:网站首页 > 代码编程 > JAVA开发JAVA开发
【原】springboot配置双数据源报错“jdbcUrl is required with driverClassName”
不忘初心 2020-01-14 围观() 评论() 点赞() 【JAVA开发】
简介:最近的springboot项目中涉及到了双数据源的配置,照着网上的教程配置时,出了一点儿小问题,启动的直接报错“Caused by: java.lang.IllegalArgumentException: jdbcUrl is required with driverClassName.”。
最近的springboot项目中涉及到了双数据源的配置,照着网上的教程配置时,出了一点儿小问题,启动的直接报错“Caused by: java.lang.IllegalArgumentException: jdbcUrl is required with driverClassName.”。
详细错误信息如下:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-11-22 17:55:40,839 default [main] ERROR o.s.b.SpringApplication 4444 - Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactorySecondary' defined in class path resource [com/zhiri/datacenter/task/conf/SecondaryConfig.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: secondaryPersistenceUnit] Unable to build Hibernate SessionFactory; nested exception is java.lang.IllegalArgumentException: jdbcUrl is required with driverClassName.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1803)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1108)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
at com.zhiri.datacenter.task.application.DataCenterApplication.main(DataCenterApplication.java:22)
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: secondaryPersistenceUnit] Unable to build Hibernate SessionFactory; nested exception is java.lang.IllegalArgumentException: jdbcUrl is required with driverClassName.
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:403)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:378)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1862)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1799)
... 15 common frames omitted
Caused by: java.lang.IllegalArgumentException: jdbcUrl is required with driverClassName.
at com.zaxxer.hikari.HikariConfig.validate(HikariConfig.java:954)
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:109)
at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:180)
at org.hibernate.hql.spi.id.IdTableHelper.executeIdTableCreationStatements(IdTableHelper.java:67)
at org.hibernate.hql.spi.id.global.GlobalTemporaryTableBulkIdStrategy.finishPreparation(GlobalTemporaryTableBulkIdStrategy.java:125)
at org.hibernate.hql.spi.id.global.GlobalTemporaryTableBulkIdStrategy.finishPreparation(GlobalTemporaryTableBulkIdStrategy.java:42)
at org.hibernate.hql.spi.id.AbstractMultiTableBulkIdStrategyImpl.prepare(AbstractMultiTableBulkIdStrategyImpl.java:88)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:313)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:462)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1249)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:391)
... 19 common frames omitted
Disconnected from the target VM, address: '127.0.0.1:55684', transport: 'socket'
jdbc配置如下:
#写库
spring.primary.datasource.url=jdbc:mysql://xxx
spring.primary.datasource.username=xxx
spring.primary.datasource.password=xxx
spring.primary.datasource.driver-class-name=com.mysql.jdbc.Driver
#读库
#spring.secondary.datasource.url=jdbc:oracle:thin:@xxx
#spring.secondary.datasource.username=xxx
#spring.secondary.datasource.password=xxx
#spring.secondary.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
最后发现确实是这个jdbc的配置有问题,在只有一个数据源的时候,直接使用的是spring.datasource.url=xxx,这个是没有问题的,但是在双数据源的时候,就不能再这么写了。
官方文档的解释:
因为连接池的实际类型没有被公开,所以在您的自定义数据源的元数据中没有生成密钥,而且在IDE中没有完成(因为DataSource接口没有暴露属性)。另外,如果您碰巧在类路径上有Hikari,那么这个基本设置就不起作用了,因为Hikari没有url属性(但是确实有一个jdbcUrl属性)。在这种情况下,您必须重写您的配置。
改进后的写法:
#写库
spring.primary.datasource.jdbc-url=jdbc:mysql://xxx
spring.primary.datasource.username=xxx
spring.primary.datasource.password=xxx
spring.primary.datasource.driver-class-name=com.mysql.jdbc.Driver
#读库
#spring.secondary.datasource.jdbc-url=jdbc:oracle:thin:@xxx
#spring.secondary.datasource.username=xxx
#spring.secondary.datasource.password=xxx
#spring.secondary.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
看完文章,有任何疑问,请加入群聊一起交流!!!
很赞哦! ()
相关文章
- JPA报错“No identifier specified for entity”的原因
- springboot整合jpa启动报错'hibernate.dialect' not set
- springboot使用jackson处理时间碰到的两个坑
- Linux不使用tomcat搭建springboot服务图文教程
- springboot项目提示“Failed to determine a suitable driver class”
- springboot打war包,部署到外部tomcat
- springboot项目在mac下启动特别慢
- 使用idea搭建springboot项目图文教程
- Spring Boot配置Druid数据源和使用教程
- springboot连接mysql报错“java.lang.IllegalArgumentException: HOUR_OF_DAY: 2 -> 3”
标签云
猜你喜欢
- IntelliJ IDEA 2019.2已经可以利用补丁永久破解激活了
- IntelliJ IDEA 2019.3利用补丁永久破解激活教程
- IntelliJ IDEA高版本最灵活的永久破解激活方法(含插件激活,时长你说了算)
- Jetbrains全家桶基于ja-netfilter的最新破解激活详细图文教程
- IntelliJ IDEA 2022.1永久破解激活教程(亲测可用,持续更新)
- 分享几个正版 IntelliJ IDEA 激活码(破解码、注册码),亲测可用,持续更新
- ja-netfilter到底需不需要mymap,2021.3.2版本激活失效?
- 如何激活idea2022.1及以上版本中的插件(亲测可用)
- 【史上最全】IntelliJ IDEA最新2022.1版本安装和激活视频教学(含插件)
- IntelliJ IDEA 2022.2 版本最新2099年永久激活方法,亲测可用,也可以开启新UI了。
站点信息
- 网站程序:spring + freemarker
- 主题模板:《今夕何夕》
- 文章统计:篇文章
- 标签管理:标签云
- 微信公众号:扫描二维码,关注我们