Skip to content

Commit 2ec186e

Browse files
committed
📦 🎉 🧪
1 parent fccfc26 commit 2ec186e

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

springboot3.0/springboot335/src/main/java/com/springboot335/springboot335/service/NewTestServiceConfig.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,19 @@ public class NewTestServiceConfig {
1313

1414

1515
@Bean("newTestService")
16-
@Scope(value = "prototype")
1716
public TestService newTestService() {
1817
return testService;
1918
}
2019

20+
/**
21+
* org.springframework.beans.factory.NoUniqueBeanDefinitionException:
22+
* No qualifying bean of type 'com.springboot335.springboot335.service.TestService' available:
23+
* expected single matching bean but found 2: testServiceImpl,newTestService
24+
*/
25+
26+
/*
27+
TestService testService = applicationContext.getBean("newTestService", TestService.class);
28+
需要指定beanName,可以正常调用
29+
*/
30+
2131
}

springboot3.0/springboot335/src/test/java/com/springboot335/springboot335/Springboot335ApplicationTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ void testTestComponent() {
6262

6363
@Test
6464
void tt01() {
65-
TestService testService = applicationContext.getBean(TestService.class);
65+
//TestService testService = applicationContext.getBean(TestService.class);
66+
TestService testService = applicationContext.getBean("newTestService", TestService.class);
6667

6768
testService.testGet(1);
6869
}

0 commit comments

Comments
 (0)