# 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>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hanfak.gitbook.io/workspace/languages/java/framework/spring/patterns/component-scan-patterns.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
