Add autoconfiguration

This commit is contained in:
Andrei Isvoran 2024-07-03 14:41:22 +03:00
parent 279baa3bfc
commit 6f182114ee
5 changed files with 28 additions and 5 deletions

View File

@ -18,8 +18,7 @@ public class LifecycleAspect {
private final LifecycleManager lifecycleManager;
@Value("${aspect.base-package}")
private String basePackage;
private final LifecycleProperties lifecycleProperties;
@Around("@annotation(org.springframework.amqp.rabbit.annotation.RabbitListener) || "
@ -31,7 +30,7 @@ public class LifecycleAspect {
public Object checkLifecycle(ProceedingJoinPoint joinPoint) throws Throwable {
String targetClassName = joinPoint.getTarget().getClass().getPackageName();
if (!targetClassName.startsWith(basePackage)) {
if (!targetClassName.startsWith(lifecycleProperties.getBasePackage())) {
return joinPoint.proceed();
}

View File

@ -0,0 +1,12 @@
package com.knecon.fforesight.lifecyclecommons;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@EnableConfigurationProperties(LifecycleProperties.class)
@ComponentScan(basePackageClasses = {LifecycleManager.class, LifecycleAspect.class})
public class LifecycleAutoconfiguration {
}

View File

@ -0,0 +1,12 @@
package com.knecon.fforesight.lifecyclecommons;
import org.springframework.boot.context.properties.ConfigurationProperties;
import lombok.Data;
@Data
@ConfigurationProperties("lifecycle")
public class LifecycleProperties {
private String basePackage;
}

View File

@ -1,2 +1,2 @@
aspect:
lifecycle:
base-package: com.knecon

View File

@ -1,2 +1,2 @@
aspect:
lifecycle:
base-package: com.knecon