diff --git a/web/querydsl/README.md b/web/querydsl/README.md
index b8aab84c5..91ae105c5 100644
--- a/web/querydsl/README.md
+++ b/web/querydsl/README.md
@@ -4,9 +4,8 @@ This example shows some of the Spring Data Querydsl integration features with Sp
## Quickstart
-1. Install MongoDB (http://www.mongodb.org/downloads, unzip, run `mkdir data`, run `bin/mongod --dbpath=data`)
-2. Build and run the app (`mvn spring-boot:run`)
-4. Access app directly via its UI (`http://localhost:8080/`).
+1. Build and run the app (`mvn spring-boot:test-run`)
+2. Access app directly via its UI (`http://localhost:8080/`).
## Interesting bits
diff --git a/web/querydsl/pom.xml b/web/querydsl/pom.xml
index 36ab136b2..d2a1c4991 100644
--- a/web/querydsl/pom.xml
+++ b/web/querydsl/pom.xml
@@ -58,20 +58,20 @@
io.github.jpenrenthymeleaf-spring-data-dialect
- 3.3.0
+ 3.6.0org.webjarsjquery
- 2.1.3
+ 3.7.1runtimeorg.webjarsbootstrap
- 3.3.4
+ 5.3.3runtime
@@ -94,6 +94,18 @@
test
+
+ org.testcontainers
+ junit-jupiter
+ test
+
+
+
+ org.springframework.boot
+ spring-boot-testcontainers
+ test
+
+
diff --git a/web/querydsl/src/main/resources/templates/index.html b/web/querydsl/src/main/resources/templates/index.html
index 6e59b3e99..1984d043a 100644
--- a/web/querydsl/src/main/resources/templates/index.html
+++ b/web/querydsl/src/main/resources/templates/index.html
@@ -23,23 +23,27 @@
Search
-
+
-
+
-
+
-
+
-
+
diff --git a/web/querydsl/src/test/java/example/users/ApplicationTests.java b/web/querydsl/src/test/java/example/users/ApplicationTests.java
index 594ea2331..0f83c0706 100644
--- a/web/querydsl/src/test/java/example/users/ApplicationTests.java
+++ b/web/querydsl/src/test/java/example/users/ApplicationTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2021 the original author or authors.
+ * Copyright 2017-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,44 +15,26 @@
*/
package example.users;
-
import org.junit.jupiter.api.Test;
-
import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.context.DynamicPropertyRegistry;
-import org.springframework.test.context.DynamicPropertySource;
+import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.testcontainers.containers.MongoDBContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
-import org.testcontainers.utility.DockerImageName;
/**
* @author Oliver Gierke
* @author Divya Srivastava
+ * @author Tim Sparg
*/
@Testcontainers
@SpringBootTest
class ApplicationTests {
- @Container //
- private static MongoDBContainer mongoDBContainer = MongoContainers.getDefaultContainer();
-
- @DynamicPropertySource
- static void setProperties(DynamicPropertyRegistry registry) {
- registry.add("spring.data.mongodb.uri", mongoDBContainer::getReplicaSetUrl);
- }
+ @Container
+ @ServiceConnection static MongoDBContainer mongoDBContainer = new MongoDBContainer("mongo:7");
@Test
void contextBootstraps() {}
- static class MongoContainers {
-
- private static final String IMAGE_NAME = "mongo:5.0";
- private static final String IMAGE_NAME_PROPERTY = "mongo.default.image.name";
-
- public static MongoDBContainer getDefaultContainer() {
- return new MongoDBContainer(DockerImageName.parse(System.getProperty(IMAGE_NAME_PROPERTY, IMAGE_NAME)))
- .withReuse(true);
- }
- }
}
diff --git a/web/querydsl/src/test/java/example/users/TestApplication.java b/web/querydsl/src/test/java/example/users/TestApplication.java
new file mode 100644
index 000000000..15f6c4842
--- /dev/null
+++ b/web/querydsl/src/test/java/example/users/TestApplication.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package example.users;
+
+import org.springframework.boot.SpringApplication;
+
+/**
+ * @author Tim Sparg
+ */
+public class TestApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.from(Application::main).with(TestcontainersConfiguration.class).run(args);
+ }
+
+}
diff --git a/web/querydsl/src/test/java/example/users/TestcontainersConfiguration.java b/web/querydsl/src/test/java/example/users/TestcontainersConfiguration.java
new file mode 100644
index 000000000..0749dc685
--- /dev/null
+++ b/web/querydsl/src/test/java/example/users/TestcontainersConfiguration.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package example.users;
+
+import org.springframework.boot.devtools.restart.RestartScope;
+import org.springframework.boot.test.context.TestConfiguration;
+import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
+import org.springframework.context.annotation.Bean;
+import org.testcontainers.containers.MongoDBContainer;
+import org.testcontainers.utility.DockerImageName;
+
+/**
+ * @author Tim Sparg
+ */
+@TestConfiguration(proxyBeanMethods = false)
+public class TestcontainersConfiguration {
+
+ @Bean
+ @ServiceConnection
+ @RestartScope
+ MongoDBContainer mongoDbContainer() {
+ return new MongoDBContainer(DockerImageName.parse("mongo:7"));
+ }
+
+}