无法获取oracle和hikaricp的驱动程序实例

时间:2018-06-25 07:46:53

标签: oracle spring-boot hikaricp

通过Springboot应用程序连接到oracle db时出现异常。 但是我可以使用sql developer连接到该数据库。

我用HikariCP连接数据库

堆栈跟踪的一部分附在此处

  

Blockquote 018-06-25 13:09:21.778错误--- [restartedMain] o.s.b.SpringApplication:应用程序启动失败   org.springframework.beans.factory.UnsatisfiedDependencyException:创建文件[******]中定义的名称为'collectionApiController'的bean时出错:通过构造函数参数1表示的不满足的依赖关系;嵌套的异常是org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为'collectionServiceImpl'的bean时出错:通过字段'collectionRepository'表示的不满足的依赖关系;嵌套的异常是org.springframework.beans.factory.UnsatisfiedDependencyException:创建文件[******]中定义的名称为'collectionRepositoryImpl'的bean时出错:通过构造函数参数0表示的不满足的依赖关系;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建在类路径资源[**** / AppConfig.class]中定义的名称为'namedParameterJdbcTemplate'的bean时出错:通过工厂方法实例化Bean失败;嵌套的异常是org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate]:工厂方法'namedParameterJdbcTemplate'引发了异常;嵌套的异常是org.springframework.beans.factory.BeanCreationException:创建在类路径资源[***** / AppConfig.class]中定义的名称为'dataSource'的bean时出错:通过工厂方法实例化Bean失败;嵌套的异常是org.springframework.beans.BeanInstantiationException:无法实例化[javax.sql.DataSource]:工厂方法'dataSource'引发了异常;嵌套的异常是java.lang.RuntimeException:无法获取jdbcUrl = ****的驱动程序实例       在org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749)处       在org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:189)处       在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1193)处       在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1095)       在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)       在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)       在org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:306)       在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)       在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)       在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)       在org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)       在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)       在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)       在org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)       在org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)       在org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)       在org.springframework.boot.SpringApplication.run(SpringApplication.java:303)       在org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)       在org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)       在lk.dialog.crm.collectionms.CollectionMsApplication.main(CollectionMsApplication.java:35)       在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处       在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)       在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)       在java.lang.reflect.Method.invoke(Method.java:497)       在org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)   引用

     

Blockquote

公共类AppConfig {

private String jdbcUrl;
private String user;
private String password;

@Bean
@Scope(SCOPE_PROTOTYPE)
public Logger logger(InjectionPoint injectionPoint) {
    return LoggerFactory.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
}

public AppConfig(@Value("${application.datasource.url}") String jdbcUrl,
                 @Value("${application.datasource.user}") String user,
                 @Value("${application.datasource.password}") String password) {
    this.jdbcUrl = jdbcUrl;
    this.user = user;
    this.password = password;



}

@Bean
public DataSource dataSource() {
    HikariConfig config = new HikariConfig();
    config.setJdbcUrl(jdbcUrl);
    config.setUsername(user);
    config.setPassword(password);
    config.setMaximumPoolSize(15);
    return new HikariDataSource(config);
}

}

  

Blockquote

1 个答案:

答案 0 :(得分:0)

对于MySQL,使用Spring Boot Framework访问我们将 driver 属性更改为 driver-class-name ,以使其正常工作。