mq-jms-spring
mq-jms-spring copied to clipboard
Enhanced Testcontainers Support
We were trying to use the mq-container with Spring Boot 3.x Testcontainers with @ServiceConnection
similar to what you can do with a PostgreSQL container:
@TestConfiguration(proxyBeanMethods = false)
public class TestcontainersConfiguration {
@Bean
@ServiceConnection
@RestartScope
PostgreSQLContainer<?> postgresContainer() {
return new PostgreSQLContainer<>(DockerImageName.parse("postgres:latest"));
}
}
Our intention is to avoid unnecessary container restarts between @SpringBootTest
s as that slows down the testing process significantly therefore @RestartScope
. Maybe more importantly @ServiceConnection
configures the correct connection properties, since Testcontainers exposes services on a random port (by default) this is crucial. So similar to PostgreSQL, we tried something like this:
@TestConfiguration(proxyBeanMethods = false)
public class TestcontainersConfiguration {
@Bean
@ServiceConnection
@RestartScope
GenericContainer<?> ibmMqTestContainer() {
return new GenericContainer<>(DockerImageName.parse("ibm-messaging/mq-container:latest"));
}
}
Resulting in the following error on startup:
org.springframework.boot.autoconfigure.service.connection.ConnectionDetailsNotFoundException: No ConnectionDetails found for source '@ServiceConnection source for Bean 'ibmMqTestContainer' defined in class path resource [TestcontainersConfiguration.class]'. You may need to add a 'name' to your @ServiceConnection annotation
After some debugging through Spring code, I guess this would require some integration to make it work, e.g. implementing some classes similar to the ActiveMQ Testcontainers integration.
- ibmmq-jms-spring version: 3.3.1
- Java version (including vendor and platform): Temurin-21.0.3+9
- A small code sample that demonstrates the issue.