【问题标题】:Add new conection to database in Jhipster在 Jhipster 中添加到数据库的新连接
【发布时间】:2016-05-21 22:00:17
【问题描述】:

我需要在一个 Jhipster 项目中做一个新的数据库连接,我正在做下一个

在application-dev.yml中添加:

 datasource:
    driver-class-name: org.postgresql.ds.PGSimpleDataSource
    url: jdbc:postgresql://localhost:5432/analytics
    name: analytics
    username: elser
    password: ******
 datasources:    
    elser:
        driver-class-name: org.hibernate.dialect.PostgreSQLDialect
        url: jdbc:postgresql://localhost:5432/elser
        name: elser
        username: elser
        password: ******

在 DatabaseConfiguration.java 中:

@Bean
@ConfigurationProperties(prefix="spring.datasources.elser")
public DataSource dataSourceElser() {
    return DataSourceBuilder.create().build();
}

我添加了一个新类来测试这个:

@Inject
@Qualifier("dataSourceElser")
private DataSource dataSourceElser;

private JdbcTemplate jdbcTemplate;

@PostConstruct
public void init() {
    jdbcTemplate = new JdbcTemplate(dataSourceElser);

    int rowCount = this.jdbcTemplate.queryForObject("select count(*)       from commons.usuario", Integer.class);
    System.out.println(rowCount);
}

但它给了我下一个错误:

 java.sql.SQLException: org.hibernate.dialect.PostgreSQLDialect cannot be cast to java.sql.Driver

【问题讨论】:

    标签: java database jdbc datasource jhipster


    【解决方案1】:

    您当前指定的是休眠方言,而不是 JDBC 驱动程序名称。你需要使用:

    driver-class-name: org.postgresql.Driver
    

    而不是driver-class-name: org.postgresql.ds.PGSimpleDataSource driver-class-name: org.hibernate.dialect.PostgreSQLDialect

    【讨论】:

      猜你喜欢
      • 2020-12-21
      • 1970-01-01
      • 1970-01-01
      • 2021-02-09
      • 1970-01-01
      • 2011-10-03
      • 1970-01-01
      • 1970-01-01
      • 2018-12-14
      相关资源
      最近更新 更多