Build a health Indicator spring boot
I would like have a health indicator in my configuration o spring boot. But I haven't managed it work. I have the next class, with @component, but when I written the url http://"mydomain"/admin/health, or http://"mydomain"/health my application doesn't retrieve anything.
@Component
public class DBHealthIndicator extends AbstractHealthIndicator {
private final AccountsService accountsService;
@Autowired
public DBHealthIndicator(AccountsService accountsService) {
if (accountsService == null) {
throw new IllegalArgumentException(
"An AccountsService is mandatory.");
}
this.accountsService = accountsService;
}
@Override
protected void doHealthCheck(Builder builder) throws Exception {
if (accountsService.getAccounts(1, 1)!= null){
builder.up();
}else{
builder.down();
}
}
}
Anyboyd can help me?
Thank you
Update:
Here my application.yml
server: servlet-path: /api port: 8080
mongodb: host: conexion port: 27017 databaseName: abc #uri: conexion
management: context-path: /admin
endpoints: health: enabled: yes shutdown: enabled: yes
logging: # Enable this to specify the path and the name of the log file. By default, it creates a # file named spring.log in the temp directory. file: /tmp/abc.log
level: com.abc: INFO