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