JAVA-12731: Move spring-session into spring-web-modules
This commit is contained in:
+12
@@ -0,0 +1,12 @@
|
||||
package com.baeldung.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);
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.baeldung.springsessionmongodb.controller;
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
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 ResponseEntity<Integer> count(HttpSession session) {
|
||||
|
||||
Integer counter = (Integer) session.getAttribute("count");
|
||||
|
||||
if (counter == null) {
|
||||
counter = 1;
|
||||
} else {
|
||||
counter++;
|
||||
}
|
||||
|
||||
session.setAttribute("count", counter);
|
||||
|
||||
return ResponseEntity.ok(counter);
|
||||
}
|
||||
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
spring.session.store-type=mongodb
|
||||
server.port=8080
|
||||
|
||||
spring.data.mongodb.host=localhost
|
||||
spring.data.mongodb.port=27017
|
||||
spring.data.mongodb.database=springboot-mongo
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user