BAEL-729 Adding custom info to actuator's /info endpoint (#1584)

* yasin.bhojawala@gmail.com

Evaluation article on Different Types of Bean Injection in Spring

* Revert "yasin.bhojawala@gmail.com"

This reverts commit 963cc51a7a15b75b550108fe4e198cd65a274032.

* Fixing compilation error and removing unused import

* Introduction to Java9 StackWalking API - yasin.bhojawala@gmail.com

Code examples for the article "Introduction to Java9 StackWalking API"

* BAEL-608 Introduction to Java9 StackWalking API

* BAEL-608 Introduction to Java9 StackWalking API

changing the test names to BDD style

* BAEL-608 Introduction to Java9 StackWalking API

correcting the typo

* BAEL-608 Introduction to Java9 StackWalking API

improving method names

* BAEL-608 Introduction to Java9 StackWalking API

test method names improvements

* BAEL-718 Quick intro to javatuples

* merging pom from master

* BAEL-722 Intro to JSONassert

* BAEL-722 Intro to JSONassert

Updated to 1.5.0

* BAEL-745 Quick Math.pow example

* BAEL-729 Adding custom info to actuator's /info endpoint
This commit is contained in:
Yasin 2017-04-04 15:58:51 +05:30 committed by maibin
parent 8da820b35a
commit a4f4301196
6 changed files with 92 additions and 1 deletions

View File

@ -0,0 +1,41 @@
package org.baeldung.boot.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "users")
public class User {
@Id
@GeneratedValue
private Integer id;
private String name;
private Integer status;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
}

View File

@ -0,0 +1,10 @@
package org.baeldung.boot.repository;
import org.baeldung.boot.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository("userRepository")
public interface UserRepository extends JpaRepository<User, Integer> {
public int countByStatus(int status);
}

View File

@ -0,0 +1,26 @@
package org.baeldung.endpoints.info;
import java.util.HashMap;
import java.util.Map;
import org.baeldung.boot.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.info.Info;
import org.springframework.boot.actuate.info.InfoContributor;
import org.springframework.stereotype.Component;
@Component
public class TotalUsersInfoContributor implements InfoContributor {
@Autowired
UserRepository userRepository;
@Override
public void contribute(Info.Builder builder) {
Map<String, Integer> userDetails = new HashMap<>();
userDetails.put("active", userRepository.countByStatus(1));
userDetails.put("inactive", userRepository.countByStatus(0));
builder.withDetail("users", userDetails);
}
}

View File

@ -2,7 +2,9 @@ server.port=8080
server.contextPath=/springbootapp
management.port=8081
management.address=127.0.0.1
#debug=true
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto = update
endpoints.shutdown.enabled=true
endpoints.jmx.domain=Spring Sample Application
@ -22,6 +24,7 @@ http.mappers.jsonPrettyPrint=true
info.app.name=Spring Sample Application
info.app.description=This is my first spring boot application G1
info.app.version=1.0.0
info.java-vendor = ${java.specification.vendor}
## Spring Security Configurations
security.user.name=admin1

View File

@ -0,0 +1,5 @@
insert into users values (1, 'Alex', 1);
insert into users values (2, 'Bob', 1);
insert into users values (3, 'John', 0);
insert into users values (4, 'Harry', 0);
insert into users values (5, 'Smith', 1);

View File

@ -0,0 +1,6 @@
create table USERS(
ID int not null AUTO_INCREMENT,
NAME varchar(100) not null,
STATUS int,
PRIMARY KEY ( ID )
);