diff --git a/spring-session/spring-session-mongodb/README.md b/spring-session/spring-session-mongodb/README.md new file mode 100644 index 0000000000..94fd1cd3e7 --- /dev/null +++ b/spring-session/spring-session-mongodb/README.md @@ -0,0 +1,4 @@ +This module is for Spring Session with JDBC tutorial. +Jira BAEL-1911 + +### Relevant Articles: diff --git a/spring-session/spring-session-mongodb/pom.xml b/spring-session/spring-session-mongodb/pom.xml new file mode 100644 index 0000000000..432715bc0e --- /dev/null +++ b/spring-session/spring-session-mongodb/pom.xml @@ -0,0 +1,51 @@ + + + 4.0.0 + com.baeldung + spring-session-jdbc + 0.0.1-SNAPSHOT + spring-session-jdbc + jar + Spring Session with JDBC tutorial + + + parent-boot-2 + com.baeldung + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.session + spring-session-jdbc + + + com.h2database + h2 + ${h2.version} + runtime + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/spring-session/spring-session-mongodb/src/main/java/springsessionmongodb/SpringSessionMongoDBApplication.java b/spring-session/spring-session-mongodb/src/main/java/springsessionmongodb/SpringSessionMongoDBApplication.java new file mode 100644 index 0000000000..c574501472 --- /dev/null +++ b/spring-session/spring-session-mongodb/src/main/java/springsessionmongodb/SpringSessionMongoDBApplication.java @@ -0,0 +1,12 @@ +package springsessionmongodb; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringSessionMongoDBApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringSessionMongoDBApplication.class, args); + } +} diff --git a/spring-session/spring-session-mongodb/src/main/java/springsessionmongodb/controller/SpringSessionMongoDBController.java b/spring-session/spring-session-mongodb/src/main/java/springsessionmongodb/controller/SpringSessionMongoDBController.java new file mode 100644 index 0000000000..50fc432d56 --- /dev/null +++ b/spring-session/spring-session-mongodb/src/main/java/springsessionmongodb/controller/SpringSessionMongoDBController.java @@ -0,0 +1,27 @@ +package springsessionmongodb.controller; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpSession; + +@RestController +public class SpringSessionMongoDBController { + + @GetMapping("/") + public String count(HttpSession session) { + + Integer counter = (Integer) session.getAttribute("count"); + + if (counter == null) { + counter = 0; + } else { + counter += 1; + } + + session.setAttribute("count", counter); + + return "

Count is "+counter+"

"; + } + +} diff --git a/spring-session/spring-session-mongodb/src/main/resources/application.properties b/spring-session/spring-session-mongodb/src/main/resources/application.properties new file mode 100644 index 0000000000..aeb7eb91ad --- /dev/null +++ b/spring-session/spring-session-mongodb/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.session.store-type=mongodb \ No newline at end of file diff --git a/spring-session/spring-session-mongodb/src/main/resources/logback.xml b/spring-session/spring-session-mongodb/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/spring-session/spring-session-mongodb/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/spring-session/spring-session-mongodb/src/test/java/baeldung/SpringContextIntegrationTest.java b/spring-session/spring-session-mongodb/src/test/java/baeldung/SpringContextIntegrationTest.java new file mode 100644 index 0000000000..b58fd46dae --- /dev/null +++ b/spring-session/spring-session-mongodb/src/test/java/baeldung/SpringContextIntegrationTest.java @@ -0,0 +1,16 @@ +package baeldung; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import springsessionmongodb.SpringSessionMongoDBApplication; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = SpringSessionMongoDBApplication.class) +public class SpringContextIntegrationTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +}