web-dev-qa-db-ja.com

java.lang.RuntimeException:ドライバーcom.mysql.cj.jdbc.Driverは、jdbcUrl、jdbc:Oracle:thin:@zzz:1527:yyyを受け入れないと主張しています

以下のエラーが発生しています。実際、SpringBatchメタデータテーブルを別のデータベース(MYSQL)に配置しようとしています。 Oracle Tablesにアクセスして、MongoDBにデータを入れたいだけです。しかし、コードを実行しているときはいつでも、SpringBatchはSpringBatchメタデータテーブルを作成しようとしています。 SpringBatchメタデータテーブルを使用しています。

Java.lang.RuntimeException: Driver com.mysql.cj.jdbc.Driver claims to not accept jdbcUrl, jdbc:Oracle:thin:@yyy:1527:test
    at com.zaxxer.hikari.util.DriverDataSource.<init>(DriverDataSource.Java:108) ~[HikariCP-3.2.0.jar:na]
    at com.zaxxer.hikari.pool.PoolBase.initializeDataSource(PoolBase.Java:336) ~[HikariCP-3.2.0.jar:na]
    at com.zaxxer.hikari.pool.PoolBase.<init>(PoolBase.Java:109) ~[HikariCP-3.2.0.jar:na]
    at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.Java:108) ~[HikariCP-3.2.0.jar:na]
    at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.Java:112) ~[HikariCP-3.2.0.jar:na]
    at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.Java:157) ~[spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.Java:115) ~[spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.Java:78) ~[spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.Java:319) ~[spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.Java:356) ~[spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.batch.support.DatabaseType.fromMetaData(DatabaseType.Java:100) ~[spring-batch-infrastructure-4.1.1.RELEASE.jar:4.1.1.RELEASE]
    at org.springframework.batch.core.repository.support.JobRepositoryFactoryBean.afterPropertiesSet(JobRepositoryFactoryBean.Java:183) ~[spring-batch-core-4.1.1.RELEASE.jar:4.1.1.RELEASE]
    at org.springframework.batch.core.configuration.annotation.DefaultBatchConfigurer.createJobRepository(DefaultBatchConfigurer.Java:134) ~[spring-batch-core-4.1.1.RELEASE.jar:4.1.1.RELEASE]
    at org.springframework.batch.core.configuration.annotation.DefaultBatchConfigurer.initialize(DefaultBatchConfigurer.Java:113) ~[spring-batch-core-4.1.1.RELEASE.jar:4.1.1.RELEASE]
    at org.springframework.batch.core.configuration.annotation.AbstractBatchConfiguration.getConfigurer(AbstractBatchConfiguration.Java:104) ~[spring-batch-core-4.1.1.RELEASE.jar:4.1.1.RELEASE]
    at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration.initialize(SimpleBatchConfiguration.Java:114) ~[spring-batch-core-4.1.1.RELEASE.jar:4.1.1.RELEASE]
    at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$ReferenceTargetSource.createObject(SimpleBatchConfiguration.Java:142) ~[spring-batch-core-4.1.1.RELEASE.jar:4.1.1.RELEASE]
    at org.springframework.aop.target.AbstractLazyCreationTargetSource.getTarget(AbstractLazyCreationTargetSource.Java:88) ~[spring-aop-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.Java:193) ~[spring-aop-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at com.Sun.proxy.$Proxy61.run(Unknown Source) ~[na:na]
    at com.mastercard.dms.reference.controller.CountryController.saveCountry(CountryController.Java:39) ~[classes/:na]
    at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_171]
    at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62) ~[na:1.8.0_171]
    at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43) ~[na:1.8.0_171]
    at Java.lang.reflect.Method.invoke(Method.Java:498) ~[na:1.8.0_171]
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.Java:189) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.Java:138) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.Java:102) ~[spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.Java:895) ~[spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.Java:800) ~[spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.Java:87) ~[spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.Java:1038) ~[spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.Java:942) ~[spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.Java:1005) ~[spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.Java:897) ~[spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.Java:634) ~[Tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.Java:882) ~[spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.Java:741) ~[Tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:231) ~[Tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:166) ~[Tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.Apache.Tomcat.websocket.server.WsFilter.doFilter(WsFilter.Java:53) ~[Tomcat-embed-websocket-9.0.16.jar:9.0.16]
    at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:193) ~[Tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:166) ~[Tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.Java:99) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.Java:107) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:193) ~[Tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:166) ~[Tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.Java:92) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.Java:107) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:193) ~[Tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:166) ~[Tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.Java:93) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.Java:107) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:193) ~[Tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:166) ~[Tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.Java:200) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.Java:107) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:193) ~[Tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:166) ~[Tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.Apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.Java:200) ~[Tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.Apache.catalina.core.StandardContextValve.invoke(StandardContextValve.Java:96) [Tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.Apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.Java:490) [Tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.Apache.catalina.core.StandardHostValve.invoke(StandardHostValve.Java:139) [Tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.Apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.Java:92) [Tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.Apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.Java:74) [Tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.Apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.Java:343) [Tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.Apache.coyote.http11.Http11Processor.service(Http11Processor.Java:408) [Tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.Apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.Java:66) [Tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.Apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.Java:834) [Tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.Apache.Tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.Java:1415) [Tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.Apache.Tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.Java:49) [Tomcat-embed-core-9.0.16.jar:9.0.16]
    at Java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.Java:1149) [na:1.8.0_171]
    at Java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.Java:624) [na:1.8.0_171]
    at org.Apache.Tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.Java:61) [Tomcat-embed-core-9.0.16.jar:9.0.16]
    at Java.lang.Thread.run(Thread.Java:748) [na:1.8.0_171]

application.properties

spring.datasource.url=jdbc:Oracle:thin:@yyy:1527:test
spring.datasource.username=USR
spring.datasource.password=USR
spring.datasource.driverClassName=Oracle.jdbc.OracleDriver


jdbc.batch.url=jdbc:mysql://localhost:3306/test?useSSL=false
jdbc.batch.username=root
jdbc.batch.password=root
jdbc.batch.driver-class-name=com.mysql.cj.jdbc.Driver

DBConfig.Java

@Configuration
@ComponentScan
public class DBConfig {
    @Bean
    @Primary
    @ConfigurationProperties("spring.datasource")
    public DataSourceProperties dataSourceProperties() {
        return new DataSourceProperties();
    }

    @Bean
    @ConfigurationProperties("jdbc.batch")
    public DataSource dataSource(DataSourceProperties properties) {
        return properties.initializeDataSourceBuilder().build();
    }
}
3
Ash_P

あなたの問題を理解したかどうかはわかりませんが、理解した場合は、2つの異なるデータベースに接続するようにプロジェクトを構成する必要があると思います。

@Configuration
@ComponentScan
public class DBConfig {
    @Bean(name="oracleDatasource")
    @Primary        
    @ConfigurationProperties(prefix = "spring.datasource")
    public DataSource drouotDatasource() {
        return DataSourceBuilder.create().build();
    }

    @Bean(name="mysqlDatasource")
    @ConfigurationProperties(prefix = "jdbc.batch")
    public DataSource moniteurDatasource() {
        return DataSourceBuilder.create().build();
    }
}
1
Meloudi