forked from KumareshBabuNS/docs-cloud-cache
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpring-SessionState.html.md.erb
149 lines (116 loc) · 5.04 KB
/
Spring-SessionState.html.md.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
---
title: Connecting a Spring Boot App to Pivotal Cloud Cache with Session State Caching
---
<a id="spring-boot-ssc"></a>
This section describes the two ways in which you can connect a Spring Boot app to PCC:
+ Using a Tomcat app with a WAR file. This is the default method for Tomcat apps.
+ Using the spring-session-data-gemfire library. This method requires that you use the correct version of these libraries.
##<a id="tomcat"></a> Use the Tomcat App
In PCC v1.1 and later, to get a Spring Boot app running with session state caching (SSC) on PCC,
you must create a WAR file using the `spring-boot-starter-tomcat` plugin instead of the `spring-boot-maven` plugin to create a JAR file.
For example, if you want your app to use SSC, you cannot use `spring-boot-maven` to build a JAR file and push your app to PCF,
because the Java buildpack does not pull in the necessary JAR files for SSC when it detects a Spring JAR file.
To build your WAR file, add this depedency to your `pom.xml`:
```xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
```
For a full example of running a Spring Boot app that connects with SSC, [run this app](https://github.com/cf-gemfire-org/http-session-caching) and use this following for your `pom.xml`:
```xml
<?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>
<groupId>io.pivotal.gemfire.demo</groupId>
<artifactId>HttpSessionCaching-Webapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>HttpSessionCaching-Webapp</name>
<description>Demo project for GemFire Http Session State caching</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
```
##<a id="spring-session"></a> Use a Spring Session Data GemFire App
You can connect your Spring app to PCC to do session state caching.
Use the correct version of the `spring-session-data-gemfire` library;
apps built for PCC v1.3.0 and later versions are compatible with
Spring Session Data GemFire v2.0.0.M2 and later versions.
###<a id=spring_session_data_gemfire></a> Upgrade PCC and Spring Session Data GemFire
1. Before your operator upgades PCC, stop your app.
This avoids breaking the app in this upgrade process.
1. Upgrade PCC. See [Upgrading Pivotal Cloud Cache](operator.html#upgrade) for details.
1. Rebuild your app using a `build.gradle` file that depends on
the correct version of Pivotal GemFire.
Here is an example `build.gradle` file:
```
version = '0.0.1-SNAPSHOT'
buildscript {
ext {
springBootVersion = '2.0.0.M3'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'idea'
idea{
module{
downloadSources = true
downloadJavadoc = true
}
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://repo.spring.io/libs-milestone" }
maven { url "https://repo.spring.io/milestone" }
maven { url "http://repo.springsource.org/simple/ext-release-local" }
maven { url "http://repo.spring.io/libs-release/" }
maven { url "https://repository.apache.org/content/repositories/snapshots" }
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web:2.0.0.M3")
compile("org.springframework.session:spring-session-data-gemfire:2.0.0.M2")
compile("io.pivotal.spring.cloud:spring-cloud-gemfire-spring-connector:1.0.0.RELEASE")
compile("io.pivotal.spring.cloud:spring-cloud-gemfire-cloudfoundry-connector:1.0.0.RELEASE")
}
```
2. Clear the session state region.
3. Start the rebuilt app.