Merge pull request #10351 from vpavic:improve-session-sample
* pr/10351: Polish "Improve Spring Session sample" Improve Spring Session samplepull/10351/merge
commit
326290b2c9
@ -1,50 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<parent>
|
|
||||||
<!-- Your own application should inherit from spring-boot-starter-parent -->
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-samples</artifactId>
|
|
||||||
<version>2.0.0.BUILD-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
<artifactId>spring-boot-sample-session-redis</artifactId>
|
|
||||||
<name>Spring Boot Session Redis Sample</name>
|
|
||||||
<description>Spring Boot Session Redis Sample</description>
|
|
||||||
<url>http://projects.spring.io/spring-boot/</url>
|
|
||||||
<organization>
|
|
||||||
<name>Pivotal Software, Inc.</name>
|
|
||||||
<url>http://www.spring.io</url>
|
|
||||||
</organization>
|
|
||||||
<properties>
|
|
||||||
<main.basedir>${basedir}/../..</main.basedir>
|
|
||||||
</properties>
|
|
||||||
<dependencies>
|
|
||||||
<!-- Compile -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.session</groupId>
|
|
||||||
<artifactId>spring-session-data-redis</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<!-- Test -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</project>
|
|
@ -0,0 +1,48 @@
|
|||||||
|
= Spring Boot Spring Session Sample
|
||||||
|
|
||||||
|
This sample demonstrates the Spring Session auto-configuration support. Spring Session
|
||||||
|
supports multiple session store types, including:
|
||||||
|
|
||||||
|
* `Redis`
|
||||||
|
* `JDBC`
|
||||||
|
* `Hazelcast`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
== Using a different session store
|
||||||
|
Initially, the project uses JDBC session store backed by an in-memory embedded H2
|
||||||
|
database. You can try out your favorite session store as explained below.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
=== Redis
|
||||||
|
Add `org.springframework.session:spring-session-data-redis` and
|
||||||
|
`spring-boot-starter-data-redis` dependencies to the project and make sure it is
|
||||||
|
configured properly (by default, a Redis instance with the default settings is expected
|
||||||
|
on your local box).
|
||||||
|
|
||||||
|
TIP: Run sample application using Redis session store using
|
||||||
|
`$mvn spring-boot:run -Predis`.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
=== JDBC
|
||||||
|
Add `org.springframework.session:spring-session-jdbc`,
|
||||||
|
`org.springframework.boot:spring-boot-starter-jdbc` and `com.h2database:h2` dependencies
|
||||||
|
to the project. An in-memory embedded H2 database is automatically configured.
|
||||||
|
|
||||||
|
TIP: Run sample application using JDBC session store with
|
||||||
|
`$mvn spring-boot:run -Pjdbc`.
|
||||||
|
|
||||||
|
Note that this profile is active by default.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
=== Hazelcast
|
||||||
|
Add `org.springframework.session:spring-session-hazelcast` and `com.hazelcast:hazelcast`
|
||||||
|
dependencies to the project to enable support for Hazelcast. Since there is a default
|
||||||
|
`hazelcast.xml` configuration file at the root of the classpath, it is used to
|
||||||
|
automatically configure the underlying `HazelcastInstance`.
|
||||||
|
|
||||||
|
TIP: Run sample application using Hazelcast session store with
|
||||||
|
`$mvn spring-boot:run -Phazelcast`.
|
@ -0,0 +1,90 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<!-- Your own application should inherit from spring-boot-starter-parent -->
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-samples</artifactId>
|
||||||
|
<version>2.0.0.BUILD-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<artifactId>spring-boot-sample-session</artifactId>
|
||||||
|
<name>Spring Boot Session Sample</name>
|
||||||
|
<description>Spring Boot Session Sample</description>
|
||||||
|
<url>http://projects.spring.io/spring-boot/</url>
|
||||||
|
<organization>
|
||||||
|
<name>Pivotal Software, Inc.</name>
|
||||||
|
<url>http://www.spring.io</url>
|
||||||
|
</organization>
|
||||||
|
<properties>
|
||||||
|
<main.basedir>${basedir}/../..</main.basedir>
|
||||||
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<!-- Compile -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- Test -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>redis</id>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.session</groupId>
|
||||||
|
<artifactId>spring-session-data-redis</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</profile>
|
||||||
|
<profile>
|
||||||
|
<id>jdbc</id>
|
||||||
|
<activation>
|
||||||
|
<activeByDefault>true</activeByDefault>
|
||||||
|
</activation>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.session</groupId>
|
||||||
|
<artifactId>spring-session-jdbc</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.h2database</groupId>
|
||||||
|
<artifactId>h2</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</profile>
|
||||||
|
<profile>
|
||||||
|
<id>hazelcast</id>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.session</groupId>
|
||||||
|
<artifactId>spring-session-hazelcast</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.hazelcast</groupId>
|
||||||
|
<artifactId>hazelcast</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
</project>
|
@ -0,0 +1,20 @@
|
|||||||
|
<hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.8.xsd"
|
||||||
|
xmlns="http://www.hazelcast.com/schema/config"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
|
|
||||||
|
<map name="spring:session:sessions">
|
||||||
|
<attributes>
|
||||||
|
<attribute extractor="org.springframework.session.hazelcast.PrincipalNameExtractor">principalName</attribute>
|
||||||
|
</attributes>
|
||||||
|
<indexes>
|
||||||
|
<index>principalName</index>
|
||||||
|
</indexes>
|
||||||
|
</map>
|
||||||
|
|
||||||
|
<network>
|
||||||
|
<join>
|
||||||
|
<multicast enabled="false"/>
|
||||||
|
</join>
|
||||||
|
</network>
|
||||||
|
|
||||||
|
</hazelcast>
|
Loading…
Reference in New Issue