-
Notifications
You must be signed in to change notification settings - Fork 41.6k
Closed
Labels
status: declinedA suggestion or change that we don't feel we should currently applyA suggestion or change that we don't feel we should currently apply
Description
Hello all
In the Spring boot docs here it says
If there is more than one bean of the requested type, qualifier metadata must be specified at field level:
@SpyBean
@Qualifier("example")
private ExampleService service;
This is not working for me on Spring boot 1.5.19.RELEASE. The simple example is
@SpringBootApplication
public class QualifierspyApplication {
public static void main(String[] args) {
SpringApplication.run(QualifierspyApplication.class, args);
}
@Primary
@Bean("simpleService1")
public SimpleService simpleService1() {
return new SimpleService("hello 1");
}
@Bean("simpleService2")
public SimpleService simpleService2() {
return new SimpleService("hello 2");
}
}
The test is
@RunWith(SpringRunner.class)
@SpringBootTest
public class QualifierspyApplicationFailingTest {
@SpyBean
@Qualifier("simpleService2")
private SimpleService simpleService2;
@Test
public void testSpy() {
Assert.assertEquals("hello 2", simpleService2.method());
}
}
The test only works if I put @SpyBean(name = "simpleService2").
If i remove @Primary it fails with
java.lang.IllegalStateException: No bean found for definition [SpyDefinition@209da20d name = '', typeToSpy = se.lolotron.qualifierspy.SimpleService, reset = AFTER]
You can find the example here.
veljkost and surapuramakhil
Metadata
Metadata
Assignees
Labels
status: declinedA suggestion or change that we don't feel we should currently applyA suggestion or change that we don't feel we should currently apply