Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- datasource:
- driverClassName: org.postgresql.Driver
- jdbcUrl: jdbc:postgresql://10.26.80.192/myDB
- username: postgres
- password:
- @Component
- public class DBHealthIndicator extends AbstractHealthIndicator {
- @Bean(name="getDataSource")
- @ConfigurationProperties(prefix="datasource")
- @Primary
- public DataSource getDataSource() {
- return DataSourceBuilder.create().build();
- }
- public DBHealthIndicator() {
- super();
- }
- private boolean result = false;
- @Bean
- @Primary
- public DataSourceHealthIndicator dbHealthIndicator() {
- return new DataSourceHealthIndicator(getDataSource(), "SELECT * FROM USERS");
- }
- @Override
- protected void doHealthCheck(Health.Builder builder) throws Exception {
- Health h = dbHealthIndicator().health();
- Status status = h.getStatus();
- if (status != null && "DOWN".equals(status.getCode())) {
- result = false;
- } else {
- result = true;
- }
- }
- public boolean isResult() {
- return result;
- }
- public void setResult(boolean result) {
- this.result = result;
- }
- }
- java.sql.SQLException: The url cannot be null
- at java.sql.DriverManager.getConnection(DriverManager.java:649)
- at java.sql.DriverManager.getConnection(DriverManager.java:208)
- .....
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement