diff --git a/docs/src/docs/asciidoc/guides/boot.adoc b/docs/src/docs/asciidoc/guides/boot.adoc index 16e8c1d0..bead88c5 100644 --- a/docs/src/docs/asciidoc/guides/boot.adoc +++ b/docs/src/docs/asciidoc/guides/boot.adoc @@ -82,8 +82,9 @@ In this instance Spring Session is backed by Redis. [[boot-redis-configuration]] == Configuring the Redis Connection -Spring Boot automatically creates a `RedisConnectionFactory` that connects Spring Session to the Redis Server. -In a production environment you need to ensure to update your configuration to point to your Redis server. For example, you can include the following in your *application.properties* +Spring Boot automatically creates a `RedisConnectionFactory` that connects Spring Session to a Redis Server on localhost on port 6379 (default port). +In a production environment you need to ensure to update your configuration to point to your Redis server. +For example, you can include the following in your *application.properties* .src/main/resources/application.properties ---- @@ -114,6 +115,12 @@ The boot Sample Application demonstrates how to use Spring Session to transparen You can run the sample by obtaining the {download-url}[source code] and invoking the following command: +[NOTE] +==== +For the sample to work, you must http://redis.io/download[install Redis 2.8+] on localhost and run it with the default port (6379). +Alternatively, you can update the `JedisConnectionFactory` to point to a Redis server. +==== + ---- $ ./gradlew :samples:boot:bootRun ---- diff --git a/docs/src/docs/asciidoc/guides/httpsession-xml.adoc b/docs/src/docs/asciidoc/guides/httpsession-xml.adoc index a410d62a..3a00673a 100644 --- a/docs/src/docs/asciidoc/guides/httpsession-xml.adoc +++ b/docs/src/docs/asciidoc/guides/httpsession-xml.adoc @@ -79,14 +79,12 @@ Add the following Spring Configuration: include::{samples-dir}httpsession-xml/src/main/webapp/WEB-INF/spring/session.xml[tags=beans] ---- -<1> We create an embedded Redis Server so that there is no need to start up Redis external of our application. -In a production application this is not necessary since we would point our connection to an external Redis instance. -<2> We use the combination of `` and `RedisHttpSessionConfiguration` because Spring Session does not yet provide XML Namespace support (see https://github.com/spring-projects/spring-session/issues/104[gh-104]). +<1> We use the combination of `` and `RedisHttpSessionConfiguration` because Spring Session does not yet provide XML Namespace support (see https://github.com/spring-projects/spring-session/issues/104[gh-104]). This creates a Spring Bean with the name of `springSessionRepositoryFilter` that implements Filter. The filter is what is in charge of replacing the `HttpSession` implementation to be backed by Spring Session. In this instance Spring Session is backed by Redis. -<3> We create a `RedisConnectionFactory` that connects Spring Session to the Redis Server. -We use a http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#xsd-config-body-schemas-context-pphc[PropertyPlaceholderConfigurer] to externalize the port location. +<2> We create a `RedisConnectionFactory` that connects Spring Session to the Redis Server. +We configure the connection to connect to localhost on the default port (6379) For more information on configuring Spring Data Redis, refer to the http://docs.spring.io/spring-data/data-redis/docs/current/reference/html/[reference documentation]. == XML Servlet Container Initialization @@ -128,6 +126,12 @@ For every request that `DelegatingFilterProxy` is invoked, the `springSessionRep You can run the sample by obtaining the {download-url}[source code] and invoking the following command: +[NOTE] +==== +For the sample to work, you must http://redis.io/download[install Redis 2.8+] on localhost and run it with the default port (6379). +Alternatively, you can update the `JedisConnectionFactory` to point to a Redis server. +==== + ---- $ ./gradlew :samples:httpsession-xml:tomcatRun ---- diff --git a/docs/src/docs/asciidoc/guides/httpsession.adoc b/docs/src/docs/asciidoc/guides/httpsession.adoc index 3ba7e3b4..6396c36d 100644 --- a/docs/src/docs/asciidoc/guides/httpsession.adoc +++ b/docs/src/docs/asciidoc/guides/httpsession.adoc @@ -78,13 +78,11 @@ Add the following Spring Configuration: include::{samples-dir}httpsession/src/main/java/sample/Config.java[tags=class] ---- -<1> We import an embedded Redis Server so that there is no need to start up Redis external of our application. -In a production application this is not necessary since we would point our connection to an external Redis instance. -<2> The `@EnableRedisHttpSession` annotation creates a Spring Bean with the name of `springSessionRepositoryFilter` that implements Filter. +<1> The `@EnableRedisHttpSession` annotation creates a Spring Bean with the name of `springSessionRepositoryFilter` that implements Filter. The filter is what is in charge of replacing the `HttpSession` implementation to be backed by Spring Session. In this instance Spring Session is backed by Redis. -<3> We create a `RedisConnectionFactory` that connects Spring Session to the Redis Server. -We use a http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#xsd-config-body-schemas-context-pphc[PropertyPlaceholderConfigurer] to externalize the port location. +<2> We create a `RedisConnectionFactory` that connects Spring Session to the Redis Server. +We configure the connection to connect to localhost on the default port (6379) For more information on configuring Spring Data Redis, refer to the http://docs.spring.io/spring-data/data-redis/docs/current/reference/html/[reference documentation]. == Java Servlet Container Initialization @@ -120,6 +118,12 @@ This ensures that the Spring Bean by the name `springSessionRepositoryFilter` is You can run the sample by obtaining the {download-url}[source code] and invoking the following command: +[NOTE] +==== +For the sample to work, you must http://redis.io/download[install Redis 2.8+] on localhost and run it with the default port (6379). +Alternatively, you can update the `JedisConnectionFactory` to point to a Redis server. +==== + ---- $ ./gradlew :samples:httpsession:tomcatRun ---- diff --git a/docs/src/docs/asciidoc/guides/rest.adoc b/docs/src/docs/asciidoc/guides/rest.adoc index 668371d3..817955fc 100644 --- a/docs/src/docs/asciidoc/guides/rest.adoc +++ b/docs/src/docs/asciidoc/guides/rest.adoc @@ -78,15 +78,13 @@ Add the following Spring Configuration: include::{samples-dir}rest/src/main/java/sample/HttpSessionConfig.java[tags=class] ---- -<1> We import an embedded Redis Server so that there is no need to start up Redis external of our application. -In a production application this is not necessary since we would point our connection to an external Redis instance. -<2> The `@EnableRedisHttpSession` annotation creates a Spring Bean with the name of `springSessionRepositoryFilter` that implements `Filter`. +<1> The `@EnableRedisHttpSession` annotation creates a Spring Bean with the name of `springSessionRepositoryFilter` that implements `Filter`. The filter is what is in charge of replacing the `HttpSession` implementation to be backed by Spring Session. In this instance Spring Session is backed by Redis. -<3> We create a `RedisConnectionFactory` that connects Spring Session to the Redis Server. -In our example, we are connecting to localhost on the default port (6379). +<2> We create a `RedisConnectionFactory` that connects Spring Session to the Redis Server. +We configure the connection to connect to localhost on the default port (6379) For more information on configuring Spring Data Redis, refer to the http://docs.spring.io/spring-data/data-redis/docs/current/reference/html/[reference documentation]. -<4> We customize Spring Session's HttpSession integration to use HTTP headers to convey the current session information instead of cookies. +<3> We customize Spring Session's HttpSession integration to use HTTP headers to convey the current session information instead of cookies. == Servlet Container Initialization @@ -121,6 +119,12 @@ NOTE: The name of our class (Initializer) does not matter. What is important is You can run the sample by obtaining the {download-url}[source code] and invoking the following command: +[NOTE] +==== +For the sample to work, you must http://redis.io/download[install Redis 2.8+] on localhost and run it with the default port (6379). +Alternatively, you can update the `JedisConnectionFactory` to point to a Redis server. +==== + ---- $ ./gradlew :samples:rest:tomcatRun ---- diff --git a/docs/src/docs/asciidoc/guides/security.adoc b/docs/src/docs/asciidoc/guides/security.adoc index ce29d878..6de661ff 100644 --- a/docs/src/docs/asciidoc/guides/security.adoc +++ b/docs/src/docs/asciidoc/guides/security.adoc @@ -77,13 +77,11 @@ Add the following Spring Configuration: include::{samples-dir}security/src/main/java/sample/Config.java[tags=class] ---- -<1> We import an embedded Redis Server so that there is no need to start up Redis external of our application. -In a production application this is not necessary since we would point our connection to an external Redis instance. -<2> The `@EnableRedisHttpSession` annotation creates a Spring Bean with the name of `springSessionRepositoryFilter` that implements Filter. +<1> The `@EnableRedisHttpSession` annotation creates a Spring Bean with the name of `springSessionRepositoryFilter` that implements Filter. The filter is what is in charge of replacing the `HttpSession` implementation to be backed by Spring Session. In this instance Spring Session is backed by Redis. -<3> We create a `RedisConnectionFactory` that connects Spring Session to the Redis Server. -In our example, we are connecting to localhost on the default port (6379). +<2> We create a `RedisConnectionFactory` that connects Spring Session to the Redis Server. +We configure the connection to connect to localhost on the default port (6379) For more information on configuring Spring Data Redis, refer to the http://docs.spring.io/spring-data/data-redis/docs/current/reference/html/[reference documentation]. == Servlet Container Initialization @@ -125,6 +123,12 @@ By extending `AbstractHttpSessionApplicationInitializer` we ensure that the Spri You can run the sample by obtaining the {download-url}[source code] and invoking the following command: +[NOTE] +==== +For the sample to work, you must http://redis.io/download[install Redis 2.8+] on localhost and run it with the default port (6379). +Alternatively, you can update the `JedisConnectionFactory` to point to a Redis server. +==== + ---- $ ./gradlew :samples:security:tomcatRun ---- diff --git a/docs/src/docs/asciidoc/guides/users.adoc b/docs/src/docs/asciidoc/guides/users.adoc index 533a32f0..3b1043b3 100644 --- a/docs/src/docs/asciidoc/guides/users.adoc +++ b/docs/src/docs/asciidoc/guides/users.adoc @@ -17,6 +17,12 @@ The users application demonstrates how to allow an application to manage multipl You can run the sample by obtaining the {download-url}[source code] and invoking the following command: +[NOTE] +==== +For the sample to work, you must http://redis.io/download[install Redis 2.8+] on localhost and run it with the default port (6379). +Alternatively, you can update the `JedisConnectionFactory` to point to a Redis server. +==== + ---- $ ./gradlew :samples:users:tomcatRun ---- diff --git a/docs/src/docs/asciidoc/guides/websocket.adoc b/docs/src/docs/asciidoc/guides/websocket.adoc index b5a37d17..313e6371 100644 --- a/docs/src/docs/asciidoc/guides/websocket.adoc +++ b/docs/src/docs/asciidoc/guides/websocket.adoc @@ -82,6 +82,12 @@ include::{samples-dir}websocket/src/main/java/sample/config/WebSecurityConfig.ja ---- ==== +[NOTE] +==== +For the sample to work, you must http://redis.io/download[install Redis 2.8+] on localhost and run it with the default port (6379). +Alternatively, you can update the `JedisConnectionFactory` to point to a Redis server. +==== + ---- $ ./gradlew :samples:websocket:bootRun ---- diff --git a/samples/boot/build.gradle b/samples/boot/build.gradle index 0f97a380..592597e0 100644 --- a/samples/boot/build.gradle +++ b/samples/boot/build.gradle @@ -17,7 +17,6 @@ group = 'samples' dependencies { compile project(':spring-session'), - project(':samples:spring-embedded-redis'), "org.springframework.boot:spring-boot-starter-redis", "org.springframework.boot:spring-boot-starter-web", "org.springframework.boot:spring-boot-starter-thymeleaf", diff --git a/samples/boot/src/main/java/sample/config/HttpSessionConfig.java b/samples/boot/src/main/java/sample/config/HttpSessionConfig.java index 1db98177..29ba85c0 100644 --- a/samples/boot/src/main/java/sample/config/HttpSessionConfig.java +++ b/samples/boot/src/main/java/sample/config/HttpSessionConfig.java @@ -15,11 +15,9 @@ */ package sample.config; -import org.springframework.session.data.redis.config.annotation.web.http.*; -import org.springframework.session.redis.embedded.EnableEmbeddedRedis; +import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; -@EnableEmbeddedRedis // tag::class[] @EnableRedisHttpSession // <1> public class HttpSessionConfig { } diff --git a/samples/httpsession-xml/build.gradle b/samples/httpsession-xml/build.gradle index 96ec9209..680aa124 100644 --- a/samples/httpsession-xml/build.gradle +++ b/samples/httpsession-xml/build.gradle @@ -8,7 +8,6 @@ sonarRunner { dependencies { compile project(':spring-session-data-redis'), - project(':samples:spring-embedded-redis'), "org.springframework:spring-web:$springVersion", jstlDependencies diff --git a/samples/httpsession-xml/src/main/webapp/WEB-INF/spring/session.xml b/samples/httpsession-xml/src/main/webapp/WEB-INF/spring/session.xml index f9849cb1..46b27fe3 100644 --- a/samples/httpsession-xml/src/main/webapp/WEB-INF/spring/session.xml +++ b/samples/httpsession-xml/src/main/webapp/WEB-INF/spring/session.xml @@ -7,14 +7,12 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> - - + - - + + \ No newline at end of file diff --git a/samples/httpsession/build.gradle b/samples/httpsession/build.gradle index f8215de3..9fb8178e 100644 --- a/samples/httpsession/build.gradle +++ b/samples/httpsession/build.gradle @@ -8,7 +8,6 @@ sonarRunner { dependencies { compile project(':spring-session-data-redis'), - project(':samples:spring-embedded-redis'), "org.springframework:spring-web:$springVersion", jstlDependencies diff --git a/samples/httpsession/src/main/java/sample/Config.java b/samples/httpsession/src/main/java/sample/Config.java index dbfa26bb..6cf4ddfc 100644 --- a/samples/httpsession/src/main/java/sample/Config.java +++ b/samples/httpsession/src/main/java/sample/Config.java @@ -18,19 +18,14 @@ package sample; import org.springframework.context.annotation.Bean; import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; -import org.springframework.session.redis.embedded.EnableEmbeddedRedis; -import org.springframework.session.redis.embedded.RedisServerPort; // tag::class[] -@EnableEmbeddedRedis // <1> -@EnableRedisHttpSession // <2> +@EnableRedisHttpSession // <1> public class Config { @Bean - public JedisConnectionFactory connectionFactory(@RedisServerPort int port) { - JedisConnectionFactory connection = new JedisConnectionFactory(); // <3> - connection.setPort(port); - return connection; + public JedisConnectionFactory connectionFactory() { + return new JedisConnectionFactory(); // <2> } } // end::class[] \ No newline at end of file diff --git a/samples/rest/build.gradle b/samples/rest/build.gradle index 66f8ab18..736f5fdb 100644 --- a/samples/rest/build.gradle +++ b/samples/rest/build.gradle @@ -8,7 +8,6 @@ sonarRunner { dependencies { compile project(':spring-session-data-redis'), - project(':samples:spring-embedded-redis'), "org.springframework:spring-webmvc:$springVersion", "org.springframework.security:spring-security-config:$springSecurityVersion", "org.springframework.security:spring-security-web:$springSecurityVersion", diff --git a/samples/rest/src/main/java/sample/HttpSessionConfig.java b/samples/rest/src/main/java/sample/HttpSessionConfig.java index de6b694b..5ef3a6c3 100644 --- a/samples/rest/src/main/java/sample/HttpSessionConfig.java +++ b/samples/rest/src/main/java/sample/HttpSessionConfig.java @@ -19,27 +19,22 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; -import org.springframework.session.redis.embedded.EnableEmbeddedRedis; -import org.springframework.session.redis.embedded.RedisServerPort; import org.springframework.session.web.http.HeaderHttpSessionStrategy; import org.springframework.session.web.http.HttpSessionStrategy; // tag::class[] @Configuration -@EnableEmbeddedRedis // <1> -@EnableRedisHttpSession // <2> +@EnableRedisHttpSession // <1> public class HttpSessionConfig { @Bean - public JedisConnectionFactory connectionFactory(@RedisServerPort int port) { - JedisConnectionFactory factory = new JedisConnectionFactory(); // <3> - factory.setPort(port); - return factory; + public JedisConnectionFactory connectionFactory() { + return new JedisConnectionFactory(); // <2> } @Bean public HttpSessionStrategy httpSessionStrategy() { - return new HeaderHttpSessionStrategy(); // <4> + return new HeaderHttpSessionStrategy(); // <3> } } // end::class[] \ No newline at end of file diff --git a/samples/security/build.gradle b/samples/security/build.gradle index 16052a37..20f643b0 100644 --- a/samples/security/build.gradle +++ b/samples/security/build.gradle @@ -8,7 +8,6 @@ sonarRunner { dependencies { compile project(':spring-session-data-redis'), - project(':samples:spring-embedded-redis'), "org.springframework:spring-web:$springVersion", "org.springframework.security:spring-security-config:$springSecurityVersion", "org.springframework.security:spring-security-web:$springSecurityVersion", diff --git a/samples/security/src/main/java/sample/Config.java b/samples/security/src/main/java/sample/Config.java index e15946aa..33e3218b 100644 --- a/samples/security/src/main/java/sample/Config.java +++ b/samples/security/src/main/java/sample/Config.java @@ -19,20 +19,15 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; -import org.springframework.session.redis.embedded.EnableEmbeddedRedis; -import org.springframework.session.redis.embedded.RedisServerPort; // tag::class[] @Configuration -@EnableEmbeddedRedis // <1> -@EnableRedisHttpSession // <2> +@EnableRedisHttpSession // <1> public class Config { @Bean - public JedisConnectionFactory connectionFactory(@RedisServerPort int port) { - JedisConnectionFactory connection = new JedisConnectionFactory(); // <3> - connection.setPort(port); - return connection; + public JedisConnectionFactory connectionFactory() { + return new JedisConnectionFactory(); // <2> } } // end::class[] \ No newline at end of file diff --git a/samples/spring-embedded-redis/build.gradle b/samples/spring-embedded-redis/build.gradle deleted file mode 100644 index c3021bcf..00000000 --- a/samples/spring-embedded-redis/build.gradle +++ /dev/null @@ -1,14 +0,0 @@ -apply from: JAVA_GRADLE - -tasks.findByPath("artifactoryPublish")?.enabled = false -sonarRunner { - skipProject = true -} - -dependencies { - compile "com.github.kstyrc:embedded-redis:$embeddedRedisVersion", - "org.springframework:spring-context:$springVersion" - - testCompile "junit:junit:$junitVersion", - "org.springframework.security:spring-security-test:$springSecurityVersion" -} \ No newline at end of file diff --git a/samples/spring-embedded-redis/src/main/java/org/springframework/session/redis/embedded/EmbeddedRedisConfiguration.java b/samples/spring-embedded-redis/src/main/java/org/springframework/session/redis/embedded/EmbeddedRedisConfiguration.java deleted file mode 100644 index c20db8bc..00000000 --- a/samples/spring-embedded-redis/src/main/java/org/springframework/session/redis/embedded/EmbeddedRedisConfiguration.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright 2002-2015 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 - * - * http://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 org.springframework.session.redis.embedded; - -import java.io.IOException; -import java.net.ServerSocket; - -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.DisposableBean; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.beans.factory.support.BeanDefinitionRegistry; -import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; -import org.springframework.core.env.ConfigurableEnvironment; -import org.springframework.core.env.PropertySource; - -import redis.embedded.RedisServer; - -/** - * Runs an embedded Redis instance. This is only necessary since we do not want - * users to have to setup a Redis instance. In a production environment, this - * would not be used since a Redis Server would be setup. - * - * @author Rob Winch - */ -@Configuration -class EmbeddedRedisConfiguration { - public static final String SERVER_PORT_PROP_NAME = "spring.redis.port"; - - @Bean - public static RedisServerBean redisServer(ConfigurableEnvironment env) { - RedisServerBean bean = new RedisServerBean(); - env.getPropertySources().addLast(bean); - return bean; - } - - @Bean - public static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer() { - return new PropertySourcesPlaceholderConfigurer(); - } - - /** - * Implements BeanDefinitionRegistryPostProcessor to ensure this Bean is initialized - * before any other Beans. Specifically, we want to ensure that the Redis Server is - * started before RedisHttpSessionConfiguration attempts to enable Keyspace - * notifications. We also want to ensure that we are able to register the - * {@link PropertySource} before any beans are initialized. - */ - static class RedisServerBean extends PropertySource implements InitializingBean, DisposableBean, BeanDefinitionRegistryPostProcessor { - private final int port = getAvailablePort(); - - private RedisServer redisServer; - - public RedisServerBean() { - super("redisServerPortPropertySource"); - } - - public void afterPropertiesSet() throws Exception { - redisServer = new RedisServer(port); - redisServer.start(); - } - - public void destroy() throws Exception { - if(redisServer != null) { - redisServer.stop(); - } - } - - public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {} - - public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {} - - @Override - public Object getProperty(String name) { - if(SERVER_PORT_PROP_NAME.equals(name)) { - return port; - } - return null; - } - - private static int getAvailablePort() { - ServerSocket socket = null; - try { - socket = new ServerSocket(0); - return socket.getLocalPort(); - } catch(IOException e) { - throw new RuntimeException(e); - } finally { - try { - if(socket != null) { - socket.close(); - } - }catch(IOException e) {} - } - } - } -} \ No newline at end of file diff --git a/samples/spring-embedded-redis/src/main/java/org/springframework/session/redis/embedded/EnableEmbeddedRedis.java b/samples/spring-embedded-redis/src/main/java/org/springframework/session/redis/embedded/EnableEmbeddedRedis.java deleted file mode 100644 index 9709eb57..00000000 --- a/samples/spring-embedded-redis/src/main/java/org/springframework/session/redis/embedded/EnableEmbeddedRedis.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2002-2015 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 - * - * http://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 org.springframework.session.redis.embedded; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; - -/** - *

- * Runs an embedded Redis instance on a random available port.This is only necessary - * sincewe do not want users to have to setup a Redis instance. In a production - * environment, this would not be used since a Redis Server would be setup. - *

- *

- * The port being used can be identified by using {@literal @RedisServerPort} on a Spring - * Bean. For example: - *

- * - *
- * {@literal @Configuration}
- * {@literal @EnableEmbeddedRedis}
- * public class RedisHttpSessionConfig {
- *
- *     {@literal @Bean}
- *     public JedisConnectionFactory connectionFactory({@literal @RedisServerPort} int port) throws Exception {
- *         JedisConnectionFactory connection = new JedisConnectionFactory();
- *         connection.setPort(port);
- *         return connection;
- *     }
- *
- * }
- * 
- * - * See spring-projects/spring-session/issues/121 for details on exposing embedded Redis - * support. - * - * @author Rob Winch - * @see RedisServerPort - * - */ -@Retention(value=java.lang.annotation.RetentionPolicy.RUNTIME) -@Target(value={java.lang.annotation.ElementType.TYPE}) -@Documented -@Import(EmbeddedRedisConfiguration.class) -@Configuration -public @interface EnableEmbeddedRedis {} diff --git a/samples/spring-embedded-redis/src/main/java/org/springframework/session/redis/embedded/RedisServerPort.java b/samples/spring-embedded-redis/src/main/java/org/springframework/session/redis/embedded/RedisServerPort.java deleted file mode 100644 index 480ddc50..00000000 --- a/samples/spring-embedded-redis/src/main/java/org/springframework/session/redis/embedded/RedisServerPort.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2002-2015 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 - * - * http://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 org.springframework.session.redis.embedded; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import org.springframework.beans.factory.annotation.Value; - -/** - * A convenience for finding the Redis Server port when using {@link EnableEmbeddedRedis}. For example: - * - *
- * {@literal @Configuration}
- * {@literal @EnableEmbeddedRedis}
- * public class RedisHttpSessionConfig {
- *
- *     {@literal @Bean}
- *     public JedisConnectionFactory connectionFactory({@literal @RedisServerPort} int port) throws Exception {
- *         JedisConnectionFactory connection = new JedisConnectionFactory();
- *         connection.setPort(port);
- *         return connection;
- *     }
- *
- * }
- * 
- * - * @author Rob Winch - */ -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) -@Retention(RetentionPolicy.RUNTIME) -@Documented -@Value("${"+EmbeddedRedisConfiguration.SERVER_PORT_PROP_NAME+"}") -public @interface RedisServerPort { } diff --git a/samples/users/build.gradle b/samples/users/build.gradle index f8215de3..9fb8178e 100644 --- a/samples/users/build.gradle +++ b/samples/users/build.gradle @@ -8,7 +8,6 @@ sonarRunner { dependencies { compile project(':spring-session-data-redis'), - project(':samples:spring-embedded-redis'), "org.springframework:spring-web:$springVersion", jstlDependencies diff --git a/samples/users/src/main/java/sample/Config.java b/samples/users/src/main/java/sample/Config.java index 93d1ed74..98c25753 100644 --- a/samples/users/src/main/java/sample/Config.java +++ b/samples/users/src/main/java/sample/Config.java @@ -19,24 +19,19 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; -import org.springframework.session.redis.embedded.EnableEmbeddedRedis; -import org.springframework.session.redis.embedded.RedisServerPort; /** * @author Rob Winch */ -@EnableEmbeddedRedis // tag::class[] @Configuration @EnableRedisHttpSession public class Config { @Bean - public JedisConnectionFactory connectionFactory(@RedisServerPort int port) { - JedisConnectionFactory connection = new JedisConnectionFactory(); - connection.setPort(port); - return connection; + public JedisConnectionFactory connectionFactory() { + return new JedisConnectionFactory(); } } // end::class[] \ No newline at end of file diff --git a/samples/websocket/build.gradle b/samples/websocket/build.gradle index 292eccc2..b535f177 100644 --- a/samples/websocket/build.gradle +++ b/samples/websocket/build.gradle @@ -18,7 +18,6 @@ group = 'samples' dependencies { compile project(':spring-session-data-redis'), - project(':samples:spring-embedded-redis'), "org.springframework.boot:spring-boot-starter-web", "org.springframework.boot:spring-boot-starter-data-jpa", "org.springframework.boot:spring-boot-starter-thymeleaf", diff --git a/samples/websocket/src/main/java/sample/config/DataSourceConfig.java b/samples/websocket/src/main/java/sample/config/DataSourceConfig.java index 05c16b6b..7c1f60f1 100644 --- a/samples/websocket/src/main/java/sample/config/DataSourceConfig.java +++ b/samples/websocket/src/main/java/sample/config/DataSourceConfig.java @@ -22,7 +22,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; -import org.springframework.session.redis.embedded.RedisServerPort; @Configuration public class DataSourceConfig { @@ -34,9 +33,7 @@ public class DataSourceConfig { } @Bean - public JedisConnectionFactory connectionFactory(@RedisServerPort int port) { - JedisConnectionFactory connection = new JedisConnectionFactory(); // <3> - connection.setPort(port); - return connection; + public JedisConnectionFactory connectionFactory() { + return new JedisConnectionFactory(); } } diff --git a/samples/websocket/src/main/java/sample/config/WebSecurityConfig.java b/samples/websocket/src/main/java/sample/config/WebSecurityConfig.java index 508d26dd..4f787e43 100644 --- a/samples/websocket/src/main/java/sample/config/WebSecurityConfig.java +++ b/samples/websocket/src/main/java/sample/config/WebSecurityConfig.java @@ -27,12 +27,10 @@ import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.data.repository.query.SecurityEvaluationContextExtension; import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; -import org.springframework.session.redis.embedded.EnableEmbeddedRedis; @Configuration @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true) -@EnableEmbeddedRedis // tag::enable-redis-httpsession[] @EnableRedisHttpSession//(maxInactiveIntervalInSeconds = 60) public class WebSecurityConfig diff --git a/settings.gradle b/settings.gradle index 5ef8d7a0..60f0c6e5 100644 --- a/settings.gradle +++ b/settings.gradle @@ -3,7 +3,6 @@ rootProject.name = 'spring-session-build' include 'docs' include 'samples:boot' -include 'samples:spring-embedded-redis' include 'samples:hazelcast' include 'samples:httpsession' include 'samples:httpsession-xml' diff --git a/spring-session/build.gradle b/spring-session/build.gradle index bbf14521..55851d9d 100644 --- a/spring-session/build.gradle +++ b/spring-session/build.gradle @@ -20,8 +20,7 @@ dependencies { "org.springframework:spring-messaging:$springVersion", "org.springframework:spring-websocket:$springVersion" provided "javax.servlet:javax.servlet-api:$servletApiVersion" - integrationTestCompile project(':samples:spring-embedded-redis'), - "redis.clients:jedis:2.4.1", + integrationTestCompile "redis.clients:jedis:2.4.1", "org.apache.commons:commons-pool2:2.2" testCompile "junit:junit:$junitVersion", diff --git a/spring-session/src/integration-test/java/org/springframework/session/data/redis/RedisOperationsSessionRepositoryITests.java b/spring-session/src/integration-test/java/org/springframework/session/data/redis/RedisOperationsSessionRepositoryITests.java index e614a636..6a185c6d 100644 --- a/spring-session/src/integration-test/java/org/springframework/session/data/redis/RedisOperationsSessionRepositoryITests.java +++ b/spring-session/src/integration-test/java/org/springframework/session/data/redis/RedisOperationsSessionRepositoryITests.java @@ -34,8 +34,6 @@ import org.springframework.session.Session; import org.springframework.session.SessionRepository; import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; import org.springframework.session.events.SessionDestroyedEvent; -import org.springframework.session.redis.embedded.EnableEmbeddedRedis; -import org.springframework.session.redis.embedded.RedisServerPort; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; @@ -124,12 +122,10 @@ public class RedisOperationsSessionRepositoryITests { @Configuration @EnableRedisHttpSession - @EnableEmbeddedRedis static class Config { @Bean - public JedisConnectionFactory connectionFactory(@RedisServerPort int port) throws Exception { + public JedisConnectionFactory connectionFactory() throws Exception { JedisConnectionFactory factory = new JedisConnectionFactory(); - factory.setPort(port); factory.setUsePool(false); return factory; } diff --git a/spring-session/src/integration-test/java/org/springframework/session/data/redis/config/annotation/web/http/EnableRedisHttpSessionExpireSessionDestroyedTests.java b/spring-session/src/integration-test/java/org/springframework/session/data/redis/config/annotation/web/http/EnableRedisHttpSessionExpireSessionDestroyedTests.java index 21b87be6..074188bc 100644 --- a/spring-session/src/integration-test/java/org/springframework/session/data/redis/config/annotation/web/http/EnableRedisHttpSessionExpireSessionDestroyedTests.java +++ b/spring-session/src/integration-test/java/org/springframework/session/data/redis/config/annotation/web/http/EnableRedisHttpSessionExpireSessionDestroyedTests.java @@ -34,8 +34,6 @@ import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.session.ExpiringSession; import org.springframework.session.SessionRepository; import org.springframework.session.events.SessionDestroyedEvent; -import org.springframework.session.redis.embedded.EnableEmbeddedRedis; -import org.springframework.session.redis.embedded.RedisServerPort; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; @@ -107,12 +105,10 @@ public class EnableRedisHttpSessionExpireSessionDestroyedTests