-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathUserAutoConfigurationRegistrar.java
More file actions
42 lines (39 loc) · 2.21 KB
/
Copy pathUserAutoConfigurationRegistrar.java
File metadata and controls
42 lines (39 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.digitalsanctuary.spring.user;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.boot.autoconfigure.AutoConfigurationPackages;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;
/**
* Dynamically registers the base package of this library with Spring Boot to ensure that its entities,
* repositories, and other Spring-managed components are properly detected and included in the application context.
*
* <p>
* This class simplifies integration by automatically registering the library's base
* package ({@code com.digitalsanctuary.spring.user}) for component scanning. It ensures that:
* <ul>
* <li>The library's repositories and entities are discovered and configured correctly.</li>
* <li>The consuming application retains its ability to automatically detect its own repositories and entities.</li>
* </ul>
*
* <p>
* This approach avoids the need for the consuming application to manually specify the library's base package or manage complex configuration,
* reducing setup effort and minimizing potential errors.
*
* <p>
* <b>Note:</b> This solution leverages {@link AutoConfigurationPackages#register} to dynamically register the library's package during the
* auto-configuration phase, ensuring compatibility with Spring Boot's component scanning and auto-configuration mechanisms.
*/
public class UserAutoConfigurationRegistrar implements ImportBeanDefinitionRegistrar {
/**
* Registers the library's base package (<i>com.digitalsanctuary.spring.user</i>) with the Spring application context to enable automatic
* detection of entities, repositories, and other components provided by the library.
*
* @param importingClassMetadata metadata of the class that imports this registrar
* @param registry the bean definition registry used to register the base package
*/
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
// Register the top-level package for the library
AutoConfigurationPackages.register(registry, "com.digitalsanctuary.spring.user");
}
}