Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
31 lines (20 sloc) 2.87 KB

Spring component finder strategies

Included in the structurizr-spring library are a number of component finder strategies that help you identify components in Spring applications, including those built using Spring Boot.

  • SpringMvcControllerComponentFinderStrategy: A component finder strategy that finds Spring MVC controllers (classes annotated @Controller).
  • SpringRestControllerComponentFinderStrategy: A component finder strategy that finds Spring REST controllers (classes annotated @RestController).
  • SpringServiceComponentFinderStrategy: A component finder strategy that finds Spring services (classes annotated @Service).
  • SpringComponentComponentFinderStrategy: A component finder strategy that finds Spring components (classes annotated @Component).
  • SpringRepositoryComponentFinderStrategy: A component finder strategy for Spring repositories (classes annotated @Repository, plus those that extend JpaRepository or CrudRepository).
  • SpringComponentFinderStrategy: A combined component finder strategy that uses all of the individual strategies listed above.

Spring naming conventions and interfaces vs implementation classes

Some of the Spring annotations (e.g. @Component, @Service and @Repository) are typically used to annotate implementation classes. For example, a JdbcCustomerRepository class might be annotated @Repository, rather than the CustomerRepository interface. This component finder strategy tries to refer to interface types rather than implementation classes, based upon the following assumptions:

  1. Having a component named CustomerRepository is preferable to JdbcCustomerRespository.
  2. Other types in the codebase will likely have a dependency on the interface type (e.g. via dependency injection) rather than being coupled to the implementation class.

Given that a class can implement any number of interfaces, for a given implementation class, the component finder strategies will try to find the interface where the name of that interface is included in the name of the implementation class (i.e. *Interface, Interface* and *Interface*). For example, the following implementation classes will match an interface named CustomerRepository:

  • JdbcCustomerRepository
  • CustomerRepositoryImpl
  • JdbcCustomerRepositoryImpl

Public vs non-public types

By default, non-public types will be ignored so that, for example, you can hide repository implementations behind services, as described at Whoops! Where did my architecture go. Use the setIncludePublicTypesOnly method to change this behaviour.


You can see an example of how to use the Spring component finder strategies in the Spring PetClinic example.

You can’t perform that action at this time.