Skip to content

Commit

Permalink
🐛 fix #1030 The Spring Boot jar fails to run when using @AiServic… (#20)
Browse files Browse the repository at this point in the history
The Spring Boot jar fails to run when using @aiservice due to
Reflections[0.10.2]

Relevant Links:   
- langchain4j/langchain4j#1030
- ronmamo/reflections#373
  • Loading branch information
clear2x authored Jul 3, 2024
1 parent cfcafd3 commit 74bf76f
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import dev.langchain4j.rag.RetrievalAugmentor;
import dev.langchain4j.rag.content.retriever.ContentRetriever;
import org.reflections.Reflections;
import org.reflections.util.ConfigurationBuilder;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
Expand All @@ -21,10 +22,7 @@
import org.springframework.context.annotation.Bean;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.*;

import static dev.langchain4j.exception.IllegalConfigurationException.illegalConfiguration;
import static dev.langchain4j.internal.Exceptions.illegalArgument;
Expand Down Expand Up @@ -155,8 +153,10 @@ private static Set<Class<?>> findAiServices(ConfigurableListableBeanFactory bean
String[] applicationBean = beanFactory.getBeanNamesForAnnotation(SpringBootApplication.class);
BeanDefinition applicationBeanDefinition = beanFactory.getBeanDefinition(applicationBean[0]);
String basePackage = applicationBeanDefinition.getResolvableType().resolve().getPackage().getName();
Reflections reflections = new Reflections(basePackage);
return reflections.getTypesAnnotatedWith(AiService.class);
Reflections reflections = new Reflections((new ConfigurationBuilder()).forPackage(basePackage));
Set<Class<?>> classes = reflections.getTypesAnnotatedWith(AiService.class);
classes.removeIf(clazz -> !clazz.getName().startsWith(basePackage));
return classes;
}

private static void addBeanReference(Class<?> beanType,
Expand Down

0 comments on commit 74bf76f

Please sign in to comment.