Advertisement
Guest User

Untitled

a guest
Nov 17th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. datasource:
  2. driverClassName: org.postgresql.Driver
  3. jdbcUrl: jdbc:postgresql://10.26.80.192/myDB
  4. username: postgres
  5. password:
  6.  
  7. @Component
  8. public class DBHealthIndicator extends AbstractHealthIndicator {
  9.  
  10. @Bean(name="getDataSource")
  11. @ConfigurationProperties(prefix="datasource")
  12. @Primary
  13. public DataSource getDataSource() {
  14. return DataSourceBuilder.create().build();
  15. }
  16.  
  17. public DBHealthIndicator() {
  18. super();
  19. }
  20.  
  21. private boolean result = false;
  22.  
  23. @Bean
  24. @Primary
  25. public DataSourceHealthIndicator dbHealthIndicator() {
  26. return new DataSourceHealthIndicator(getDataSource(), "SELECT * FROM USERS");
  27. }
  28.  
  29. @Override
  30. protected void doHealthCheck(Health.Builder builder) throws Exception {
  31.  
  32. Health h = dbHealthIndicator().health();
  33. Status status = h.getStatus();
  34. if (status != null && "DOWN".equals(status.getCode())) {
  35. result = false;
  36. } else {
  37. result = true;
  38. }
  39. }
  40.  
  41. public boolean isResult() {
  42. return result;
  43. }
  44.  
  45. public void setResult(boolean result) {
  46. this.result = result;
  47. }
  48.  
  49. }
  50.  
  51. java.sql.SQLException: The url cannot be null
  52. at java.sql.DriverManager.getConnection(DriverManager.java:649)
  53. at java.sql.DriverManager.getConnection(DriverManager.java:208)
  54. .....
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement