Created
July 1, 2021 10:05
-
-
Save zachpendleton/3467395ad666dc152fc11ce4124b6f95 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
management: | |
endpoints: | |
web: | |
exposure: | |
include: | |
- course | |
- health | |
- beans | |
server: | |
port: 3000 # run on a port that is not exposed on the firewall or security group | |
address: 127.0.0.1 # restrict to requests from localhost |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.demo.actuator; | |
import com.example.demo.model.Course; | |
import com.example.demo.repository.CoursesRepository; | |
import java.util.List; | |
import org.springframework.boot.actuate.endpoint.annotation.Endpoint; | |
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; | |
import org.springframework.boot.actuate.endpoint.annotation.WriteOperation; | |
import org.springframework.stereotype.Component; | |
@Endpoint(id = "course") | |
@Component | |
public class CreateCourseActuator { | |
private CoursesRepository repository; | |
public CreateCourseActuator(CoursesRepository repository) { | |
this.repository = repository; | |
} | |
@ReadOperation | |
public List<Course> readCourses() { | |
return repository.findAll(); | |
} | |
@WriteOperation | |
public void createCourse(String name) { | |
repository.create(new Course(name)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment