TIL: Spring Boot, pt5

Last day of this tutorial series. It definitely lost steam towards the end, with the last few lessons feeling pretty rushed and clustered. Made it through to the end, but I feel like I got much more out of the last 4 days than today.

Today I’ll be moving on to something else, so enjoy the last of my notes.

Creating Your Own Repository Search Method

  • The JPA does this really neat thing where it’ll basically take care of writing all of your method code for you if you write your method name a very specific way
  • The format of the method names is findBy<item>, where item is the property that you’re looking for
  • For example, If I wanted to find something by its name, I could do the following:
1
2
3
4
public interface CourseRepository extends CrudRepository<Course, String> {

   public List<Course> findByName(String name);
}
  • If I wanted to look for a property of an object (lets say the object’s name is Topic), it would look like this:
1
2
3
4
public interface CourseRepository extends CrudRepository<Course, String> {

   public List<Course> findByTopicId(String topicId);
}
  • The JPA will handle the rest and do the correct look up for you. You just use this created method over in your service logic.

Packaging and Running the Spring Boot App

  • Install using mvn clean install

Actuator

  • Creates a new set of endpoints for checking the health status of your application
  • Just another set of jars that can be grabbed when creating your project or added to your pom file
  • Full list of what it gives

💚