dimanche 14 avril 2019

Load 1 bean from @configuration in SpringBoot

PIDClient has HttpClient (Java 11) as a dependency in its constructor. I want to autowire this so I created an @Configuration annotated class named SpringConfiguration. I got it working with the code below.

@RunWith(SpringRunner.class)
@SpringBootTest(classes = {PIDClient.class, SpringConfiguration.class})
public class PIDClientTest {

My issue with this is, now it loads all the beans in SpringConfiguration while I only need HttpClient bean. I tried the code below but that gave me a No qualifying bean of type 'java.net.http.HttpClient'.

@RunWith(SpringRunner.class)
@SpringBootTest(classes = {PIDClient.class, HttpClient.class})
public class PIDClientTest {

Here's a screenshot of the projects' directory structure in case it's needed with the relevant classes open. enter image description here

Is there a better way?

Aucun commentaire:

Enregistrer un commentaire