fix: BeannameGenerator 적용

dev
minuk926 3 years ago
parent 3e21f26348
commit b12c0a6371

@ -1,56 +0,0 @@
package com.xit.core.config._ignore;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.context.annotation.AnnotationBeanNameGenerator;
import org.springframework.lang.NonNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* ,
*
*
* .
*
* /v1/api, /v2/api
*/
public class CustomBeanNameGenerator implements BeanNameGenerator {
/**
* basePackages scaning beanGenerator
*/
private static final BeanNameGenerator DELEGATE = new AnnotationBeanNameGenerator();
/**
* VersioningBeanNameGenerator package
*/
private final List<String> basePackages = new ArrayList<>(
Arrays.asList("com.xit.biz", "com.xit.core")
);
@Override
public @NonNull String generateBeanName(@NonNull BeanDefinition definition, @NonNull BeanDefinitionRegistry registry) {
if(isTargetPackageBean(definition)) {
return getBeanName(definition);
}
return DELEGATE.generateBeanName(definition, registry);
}
private boolean isTargetPackageBean(BeanDefinition definition) {
String beanClassName = getBeanName(definition);
return basePackages.stream().anyMatch(beanClassName::startsWith);
}
private String getBeanName(BeanDefinition definition) {
return definition.getBeanClassName();
}
public void addBasePackages(String path) {
this.basePackages.add(path);
}
}

@ -1,54 +0,0 @@
package com.xit.core.config._ignore;
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.context.annotation.AnnotationBeanNameGenerator;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Service;
import java.util.Set;
/**
* <pre>
* ,
*
*
* .
*
* /v1/api, /v2/api
* </pre>
*/
public class CustomBeanNameGenerator2 implements BeanNameGenerator {
private final AnnotationBeanNameGenerator defaultNameGenerator = new AnnotationBeanNameGenerator();
@Override
public @NonNull String generateBeanName(@NonNull BeanDefinition definition, @NonNull BeanDefinitionRegistry registry) {
String beanName;
if (isService(definition)) {
beanName = getFullName((AnnotatedBeanDefinition) definition);
} else {
beanName = defaultNameGenerator.generateBeanName(definition, registry);
}
return beanName;
}
private String getFullName(final AnnotatedBeanDefinition definition) {
// 패키지를 포함한 전체 이름을 반환한다.
return definition.getMetadata().getClassName();
}
private boolean isService(final BeanDefinition definition) {
if (definition instanceof AnnotatedBeanDefinition) {
final Set<String> annotationTypes = ((AnnotatedBeanDefinition) definition).getMetadata()
.getAnnotationTypes();
return annotationTypes.stream()
.anyMatch(type -> type.equals(Service.class.getName()));
}
return false;
}
}

@ -17,7 +17,7 @@ api:
file:
cmm:
upload:
root: /data/file/upload
root: c:/data/file/upload
# root: /Users/minuk/data/file/upload
# 공지사항
path: /kangnamSIM/simUpFile

Loading…
Cancel
Save