-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #2133 Spring boot starter breaks configuration classes (#79)
Fixes langchain4j/langchain4j#2133 The problem is `beanfactory.getBeanswithanNotation()`. It creates an instance of the Bean in advance. https://github.com/langchain4j/langchain4j-spring/blob/405fddafbcf8c3463c7211dc82b7c5887f9531c6/langchain4j-spring-boot-starter/src/main/java/dev/langchain4j/service/spring/AiServiceScannerProcessor.java#L49
- Loading branch information
Showing
4 changed files
with
82 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...langchain4j/service/spring/mode/automatic/Issue2133/TestAutowireAiServiceApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package dev.langchain4j.service.spring.mode.automatic.Issue2133; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
/** | ||
* @author: qing | ||
* @Date: 2024/11/20 | ||
*/ | ||
@SpringBootApplication | ||
public class TestAutowireAiServiceApplication { | ||
|
||
@Autowired | ||
TestAutowireConfiguration testAutowireConfiguration; | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(TestAutowireAiServiceApplication.class, args); | ||
} | ||
|
||
TestAutowireConfiguration getConfiguration() { | ||
return testAutowireConfiguration; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...dev/langchain4j/service/spring/mode/automatic/Issue2133/TestAutowireClassAiServiceIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package dev.langchain4j.service.spring.mode.automatic.Issue2133; | ||
|
||
import dev.langchain4j.service.spring.AiServicesAutoConfig; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.autoconfigure.AutoConfigurations; | ||
import org.springframework.boot.test.context.runner.ApplicationContextRunner; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
class TestAutowireClassAiServiceIT { | ||
|
||
ApplicationContextRunner contextRunner = new ApplicationContextRunner() | ||
.withConfiguration(AutoConfigurations.of(AiServicesAutoConfig.class)); | ||
|
||
@Test | ||
void should_get_configuration_class() { | ||
contextRunner | ||
.withUserConfiguration(TestAutowireAiServiceApplication.class) | ||
.withBean(TestAutowireConfiguration.class) | ||
.run(context -> { | ||
// given | ||
TestAutowireAiServiceApplication application = context.getBean(TestAutowireAiServiceApplication.class); | ||
|
||
// should get the configuration class | ||
assertNotNull(application.getConfiguration(), "TestConfiguration class should be not null"); | ||
}); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...va/dev/langchain4j/service/spring/mode/automatic/Issue2133/TestAutowireConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package dev.langchain4j.service.spring.mode.automatic.Issue2133; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* @author: qing | ||
* @Date: 2024/11/20 | ||
*/ | ||
@Configuration | ||
class TestAutowireConfiguration { | ||
} |