Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NatsAutoConfiguration.class breaks (@WebMvcTest) tests #44

Open
mythicallage opened this issue May 27, 2024 · 0 comments
Open

NatsAutoConfiguration.class breaks (@WebMvcTest) tests #44

mythicallage opened this issue May 27, 2024 · 0 comments

Comments

@mythicallage
Copy link

Context case:

I'm trying to test only one controller like:

@WebMvcTest(UserController.class)
public class UserControllerTest {
// some tests here
}

And then I've got like this:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'natsConnection' defined in class path resource [io/nats/spring/boot/autoconfigure/NatsAutoConfiguration.class]: Failed to instantiate [io.nats.client.Connection]: Factory method 'natsConnection' threw exception with message: Unable to connect to NATS servers: [nats://localhost:4222]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:648)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:636)

The spring boot 3.x only has dependencies with default beans:

        <dependency>
            <groupId>io.nats</groupId>
            <artifactId>jnats</artifactId>
            <version>2.18.1</version>
        </dependency>

        <dependency>
            <groupId>io.nats</groupId>
            <artifactId>nats-spring</artifactId>
            <version>0.5.7</version>
        </dependency>

Solve. I have to write tests every time like below:

@WebMvcTest(value = UserController.class, excludeAutoConfiguration = NatsAutoConfiguration.class)
public class UserControllerTest {
// some tests here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant