> For the complete documentation index, see [llms.txt](https://hanfak.gitbook.io/workspace/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hanfak.gitbook.io/workspace/languages/java/framework/spring/patterns/component-scan-patterns.md).

# Component Scan Patterns

## Hexagonal Architecture

* The core should have be framework agnostic, this can be hard to do in Spring
  * Will either have to
    * Ignore the sterotypes (ie @Component) which can lead to even more spring stuff to inflitrate the domain
      * This can be a valid way, but most be strict, could use archunit to only allow sterotypes in the domain
    * Or Create Configuration files and beans, where you manually instantiate everything
* Instead you can use use component scan another way, by creating custom annotations (ie @Domain) inside the domain, and have the infrastructure do the mapping on those custom annotations to the component scan
  * limitations
    * If you need some conditional or profile-based bean construction, you will have to switch back to a bean factory.

### Links

* <https://beyondxscratch.com/2019/07/28/domaindrivendesign-hexagonalarchitecture-tips-tricks-binding-the-domain-to-the-spring-context-with-componentscan/>
* <https://gitlab.com/beyondxscratch/hexagonal-architecture-java-springboot/-/tree/main?ref\\_type=heads>
