diff --git a/samples/javaconfig/custom-cookie/spring-session-sample-javaconfig-custom-cookie.gradle b/samples/javaconfig/custom-cookie/spring-session-sample-javaconfig-custom-cookie.gradle index 731df52b..7e38f8af 100644 --- a/samples/javaconfig/custom-cookie/spring-session-sample-javaconfig-custom-cookie.gradle +++ b/samples/javaconfig/custom-cookie/spring-session-sample-javaconfig-custom-cookie.gradle @@ -8,6 +8,7 @@ dependencies { compile "org.webjars:webjars-taglib" compile jstlDependencies compile slf4jDependencies + compile "org.testcontainers:testcontainers" providedCompile "javax.servlet:javax.servlet-api" @@ -16,3 +17,7 @@ dependencies { integrationTestCompile seleniumDependencies } + +gretty { + jvmArgs = ['-Dspring.profiles.active=embedded-redis'] +} diff --git a/samples/javaconfig/custom-cookie/src/main/java/sample/Config.java b/samples/javaconfig/custom-cookie/src/main/java/sample/Config.java index 92bff82f..25b18d3f 100644 --- a/samples/javaconfig/custom-cookie/src/main/java/sample/Config.java +++ b/samples/javaconfig/custom-cookie/src/main/java/sample/Config.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2017 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. @@ -17,11 +17,13 @@ package sample; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Import; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; import org.springframework.session.web.http.CookieSerializer; import org.springframework.session.web.http.DefaultCookieSerializer; +@Import(EmbeddedRedisConfig.class) @EnableRedisHttpSession public class Config { diff --git a/samples/javaconfig/custom-cookie/src/main/java/sample/EmbeddedRedisConfig.java b/samples/javaconfig/custom-cookie/src/main/java/sample/EmbeddedRedisConfig.java new file mode 100644 index 00000000..4e8af65c --- /dev/null +++ b/samples/javaconfig/custom-cookie/src/main/java/sample/EmbeddedRedisConfig.java @@ -0,0 +1,59 @@ +/* + * Copyright 2014-2017 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 sample; + +import java.io.IOException; + +import org.testcontainers.containers.GenericContainer; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.context.annotation.Profile; +import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; + +@Configuration +@Profile("embedded-redis") +public class EmbeddedRedisConfig { + + private static final String REDIS_DOCKER_IMAGE = "redis:3.2.9"; + + @Bean(initMethod = "start") + public GenericContainer redisContainer() { + return new GenericContainer(REDIS_DOCKER_IMAGE) { + + @Override + public void close() { + super.close(); + try { + this.dockerClient.close(); + } + catch (IOException ignored) { + } + } + + }.withExposedPorts(6379); + } + + @Bean + @Primary + public LettuceConnectionFactory redisConnectionFactory() { + return new LettuceConnectionFactory(redisContainer().getContainerIpAddress(), + redisContainer().getFirstMappedPort()); + } + +} diff --git a/samples/javaconfig/redis/spring-session-sample-javaconfig-redis.gradle b/samples/javaconfig/redis/spring-session-sample-javaconfig-redis.gradle index 731df52b..7e38f8af 100644 --- a/samples/javaconfig/redis/spring-session-sample-javaconfig-redis.gradle +++ b/samples/javaconfig/redis/spring-session-sample-javaconfig-redis.gradle @@ -8,6 +8,7 @@ dependencies { compile "org.webjars:webjars-taglib" compile jstlDependencies compile slf4jDependencies + compile "org.testcontainers:testcontainers" providedCompile "javax.servlet:javax.servlet-api" @@ -16,3 +17,7 @@ dependencies { integrationTestCompile seleniumDependencies } + +gretty { + jvmArgs = ['-Dspring.profiles.active=embedded-redis'] +} diff --git a/samples/javaconfig/redis/src/main/java/sample/Config.java b/samples/javaconfig/redis/src/main/java/sample/Config.java index 4a03dd74..69f8b94f 100644 --- a/samples/javaconfig/redis/src/main/java/sample/Config.java +++ b/samples/javaconfig/redis/src/main/java/sample/Config.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2017 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. @@ -17,9 +17,11 @@ package sample; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Import; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; +@Import(EmbeddedRedisConfig.class) // tag::class[] @EnableRedisHttpSession // <1> public class Config { diff --git a/samples/javaconfig/redis/src/main/java/sample/EmbeddedRedisConfig.java b/samples/javaconfig/redis/src/main/java/sample/EmbeddedRedisConfig.java new file mode 100644 index 00000000..4e8af65c --- /dev/null +++ b/samples/javaconfig/redis/src/main/java/sample/EmbeddedRedisConfig.java @@ -0,0 +1,59 @@ +/* + * Copyright 2014-2017 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 sample; + +import java.io.IOException; + +import org.testcontainers.containers.GenericContainer; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.context.annotation.Profile; +import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; + +@Configuration +@Profile("embedded-redis") +public class EmbeddedRedisConfig { + + private static final String REDIS_DOCKER_IMAGE = "redis:3.2.9"; + + @Bean(initMethod = "start") + public GenericContainer redisContainer() { + return new GenericContainer(REDIS_DOCKER_IMAGE) { + + @Override + public void close() { + super.close(); + try { + this.dockerClient.close(); + } + catch (IOException ignored) { + } + } + + }.withExposedPorts(6379); + } + + @Bean + @Primary + public LettuceConnectionFactory redisConnectionFactory() { + return new LettuceConnectionFactory(redisContainer().getContainerIpAddress(), + redisContainer().getFirstMappedPort()); + } + +} diff --git a/samples/javaconfig/rest/spring-session-sample-javaconfig-rest.gradle b/samples/javaconfig/rest/spring-session-sample-javaconfig-rest.gradle index f994813f..819575c6 100644 --- a/samples/javaconfig/rest/spring-session-sample-javaconfig-rest.gradle +++ b/samples/javaconfig/rest/spring-session-sample-javaconfig-rest.gradle @@ -9,6 +9,7 @@ dependencies { compile "com.fasterxml.jackson.core:jackson-databind" compile jstlDependencies compile slf4jDependencies + compile "org.testcontainers:testcontainers" providedCompile "javax.servlet:javax.servlet-api" @@ -20,3 +21,7 @@ dependencies { integrationTestCompile "org.testcontainers:testcontainers" } + +gretty { + jvmArgs = ['-Dspring.profiles.active=embedded-redis'] +} diff --git a/samples/javaconfig/rest/src/main/java/sample/EmbeddedRedisConfig.java b/samples/javaconfig/rest/src/main/java/sample/EmbeddedRedisConfig.java new file mode 100644 index 00000000..4e8af65c --- /dev/null +++ b/samples/javaconfig/rest/src/main/java/sample/EmbeddedRedisConfig.java @@ -0,0 +1,59 @@ +/* + * Copyright 2014-2017 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 sample; + +import java.io.IOException; + +import org.testcontainers.containers.GenericContainer; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.context.annotation.Profile; +import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; + +@Configuration +@Profile("embedded-redis") +public class EmbeddedRedisConfig { + + private static final String REDIS_DOCKER_IMAGE = "redis:3.2.9"; + + @Bean(initMethod = "start") + public GenericContainer redisContainer() { + return new GenericContainer(REDIS_DOCKER_IMAGE) { + + @Override + public void close() { + super.close(); + try { + this.dockerClient.close(); + } + catch (IOException ignored) { + } + } + + }.withExposedPorts(6379); + } + + @Bean + @Primary + public LettuceConnectionFactory redisConnectionFactory() { + return new LettuceConnectionFactory(redisContainer().getContainerIpAddress(), + redisContainer().getFirstMappedPort()); + } + +} diff --git a/samples/javaconfig/rest/src/main/java/sample/HttpSessionConfig.java b/samples/javaconfig/rest/src/main/java/sample/HttpSessionConfig.java index 5fc10a6c..80fd9c7c 100644 --- a/samples/javaconfig/rest/src/main/java/sample/HttpSessionConfig.java +++ b/samples/javaconfig/rest/src/main/java/sample/HttpSessionConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2017 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. @@ -18,11 +18,13 @@ package sample; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; import org.springframework.session.web.http.HeaderHttpSessionStrategy; import org.springframework.session.web.http.HttpSessionStrategy; +@Import(EmbeddedRedisConfig.class) // tag::class[] @Configuration @EnableRedisHttpSession // <1> diff --git a/samples/javaconfig/security/spring-session-sample-javaconfig-security.gradle b/samples/javaconfig/security/spring-session-sample-javaconfig-security.gradle index 82c3da0b..fa4e092a 100644 --- a/samples/javaconfig/security/spring-session-sample-javaconfig-security.gradle +++ b/samples/javaconfig/security/spring-session-sample-javaconfig-security.gradle @@ -10,6 +10,7 @@ dependencies { compile "org.webjars:webjars-taglib" compile jstlDependencies compile slf4jDependencies + compile "org.testcontainers:testcontainers" providedCompile "javax.servlet:javax.servlet-api" providedCompile "javax.servlet.jsp:javax.servlet.jsp-api" @@ -20,3 +21,7 @@ dependencies { integrationTestCompile seleniumDependencies } + +gretty { + jvmArgs = ['-Dspring.profiles.active=embedded-redis'] +} diff --git a/samples/javaconfig/security/src/main/java/sample/Config.java b/samples/javaconfig/security/src/main/java/sample/Config.java index 384e090a..660c2ed0 100644 --- a/samples/javaconfig/security/src/main/java/sample/Config.java +++ b/samples/javaconfig/security/src/main/java/sample/Config.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2017 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. @@ -18,9 +18,11 @@ package sample; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; +@Import(EmbeddedRedisConfig.class) // tag::class[] @Configuration @EnableRedisHttpSession // <1> diff --git a/samples/javaconfig/security/src/main/java/sample/EmbeddedRedisConfig.java b/samples/javaconfig/security/src/main/java/sample/EmbeddedRedisConfig.java new file mode 100644 index 00000000..4e8af65c --- /dev/null +++ b/samples/javaconfig/security/src/main/java/sample/EmbeddedRedisConfig.java @@ -0,0 +1,59 @@ +/* + * Copyright 2014-2017 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 sample; + +import java.io.IOException; + +import org.testcontainers.containers.GenericContainer; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.context.annotation.Profile; +import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; + +@Configuration +@Profile("embedded-redis") +public class EmbeddedRedisConfig { + + private static final String REDIS_DOCKER_IMAGE = "redis:3.2.9"; + + @Bean(initMethod = "start") + public GenericContainer redisContainer() { + return new GenericContainer(REDIS_DOCKER_IMAGE) { + + @Override + public void close() { + super.close(); + try { + this.dockerClient.close(); + } + catch (IOException ignored) { + } + } + + }.withExposedPorts(6379); + } + + @Bean + @Primary + public LettuceConnectionFactory redisConnectionFactory() { + return new LettuceConnectionFactory(redisContainer().getContainerIpAddress(), + redisContainer().getFirstMappedPort()); + } + +} diff --git a/samples/javaconfig/users/spring-session-sample-javaconfig-users.gradle b/samples/javaconfig/users/spring-session-sample-javaconfig-users.gradle index c4283900..46d6c4f9 100644 --- a/samples/javaconfig/users/spring-session-sample-javaconfig-users.gradle +++ b/samples/javaconfig/users/spring-session-sample-javaconfig-users.gradle @@ -8,6 +8,7 @@ dependencies { compile "org.webjars:webjars-taglib" compile jstlDependencies compile slf4jDependencies + compile "org.testcontainers:testcontainers" providedCompile "javax.servlet:javax.servlet-api" @@ -17,3 +18,7 @@ dependencies { integrationTestCompile seleniumDependencies } + +gretty { + jvmArgs = ['-Dspring.profiles.active=embedded-redis'] +} diff --git a/samples/javaconfig/users/src/main/java/sample/Config.java b/samples/javaconfig/users/src/main/java/sample/Config.java index 2356e748..6fc53cdd 100644 --- a/samples/javaconfig/users/src/main/java/sample/Config.java +++ b/samples/javaconfig/users/src/main/java/sample/Config.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2017 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. @@ -18,13 +18,14 @@ package sample; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; /** * @author Rob Winch */ - +@Import(EmbeddedRedisConfig.class) // tag::class[] @Configuration @EnableRedisHttpSession diff --git a/samples/javaconfig/users/src/main/java/sample/EmbeddedRedisConfig.java b/samples/javaconfig/users/src/main/java/sample/EmbeddedRedisConfig.java new file mode 100644 index 00000000..4e8af65c --- /dev/null +++ b/samples/javaconfig/users/src/main/java/sample/EmbeddedRedisConfig.java @@ -0,0 +1,59 @@ +/* + * Copyright 2014-2017 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 sample; + +import java.io.IOException; + +import org.testcontainers.containers.GenericContainer; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.context.annotation.Profile; +import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; + +@Configuration +@Profile("embedded-redis") +public class EmbeddedRedisConfig { + + private static final String REDIS_DOCKER_IMAGE = "redis:3.2.9"; + + @Bean(initMethod = "start") + public GenericContainer redisContainer() { + return new GenericContainer(REDIS_DOCKER_IMAGE) { + + @Override + public void close() { + super.close(); + try { + this.dockerClient.close(); + } + catch (IOException ignored) { + } + } + + }.withExposedPorts(6379); + } + + @Bean + @Primary + public LettuceConnectionFactory redisConnectionFactory() { + return new LettuceConnectionFactory(redisContainer().getContainerIpAddress(), + redisContainer().getFirstMappedPort()); + } + +} diff --git a/samples/xml/redis/spring-session-sample-xml-redis.gradle b/samples/xml/redis/spring-session-sample-xml-redis.gradle index 731df52b..7e38f8af 100644 --- a/samples/xml/redis/spring-session-sample-xml-redis.gradle +++ b/samples/xml/redis/spring-session-sample-xml-redis.gradle @@ -8,6 +8,7 @@ dependencies { compile "org.webjars:webjars-taglib" compile jstlDependencies compile slf4jDependencies + compile "org.testcontainers:testcontainers" providedCompile "javax.servlet:javax.servlet-api" @@ -16,3 +17,7 @@ dependencies { integrationTestCompile seleniumDependencies } + +gretty { + jvmArgs = ['-Dspring.profiles.active=embedded-redis'] +} diff --git a/samples/xml/redis/src/main/java/sample/EmbeddedRedisConfig.java b/samples/xml/redis/src/main/java/sample/EmbeddedRedisConfig.java new file mode 100644 index 00000000..4e8af65c --- /dev/null +++ b/samples/xml/redis/src/main/java/sample/EmbeddedRedisConfig.java @@ -0,0 +1,59 @@ +/* + * Copyright 2014-2017 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 sample; + +import java.io.IOException; + +import org.testcontainers.containers.GenericContainer; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.context.annotation.Profile; +import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; + +@Configuration +@Profile("embedded-redis") +public class EmbeddedRedisConfig { + + private static final String REDIS_DOCKER_IMAGE = "redis:3.2.9"; + + @Bean(initMethod = "start") + public GenericContainer redisContainer() { + return new GenericContainer(REDIS_DOCKER_IMAGE) { + + @Override + public void close() { + super.close(); + try { + this.dockerClient.close(); + } + catch (IOException ignored) { + } + } + + }.withExposedPorts(6379); + } + + @Bean + @Primary + public LettuceConnectionFactory redisConnectionFactory() { + return new LettuceConnectionFactory(redisContainer().getContainerIpAddress(), + redisContainer().getFirstMappedPort()); + } + +} diff --git a/samples/xml/redis/src/main/webapp/WEB-INF/spring/session.xml b/samples/xml/redis/src/main/webapp/WEB-INF/spring/session.xml index 4b569357..62f9b246 100644 --- a/samples/xml/redis/src/main/webapp/WEB-INF/spring/session.xml +++ b/samples/xml/redis/src/main/webapp/WEB-INF/spring/session.xml @@ -15,4 +15,7 @@ - \ No newline at end of file + + + +