3
新的連接如數據庫添加我需要做的Jhipster項目新的數據庫連接,我做下一個在Jhipster
添加在應用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