From 38309e97a8339c6d659625fd842bf83f4765d26f Mon Sep 17 00:00:00 2001 From: John Blum Date: Mon, 13 Aug 2018 16:56:10 -0700 Subject: [PATCH] Refactor the Spring Session JavaConfig Sample to use Spring Data for Apache Geode Test. --- ...ple-javaconfig-gemfire-clientserver.gradle | 1 + .../src/main/java/sample/ClientConfig.java | 23 +++---------------- .../src/main/java/sample/ServerConfig.java | 21 +++-------------- 3 files changed, 7 insertions(+), 38 deletions(-) diff --git a/samples/javaconfig/gemfire-clientserver/spring-session-sample-javaconfig-gemfire-clientserver.gradle b/samples/javaconfig/gemfire-clientserver/spring-session-sample-javaconfig-gemfire-clientserver.gradle index 15fb96c..d810b2e 100644 --- a/samples/javaconfig/gemfire-clientserver/spring-session-sample-javaconfig-gemfire-clientserver.gradle +++ b/samples/javaconfig/gemfire-clientserver/spring-session-sample-javaconfig-gemfire-clientserver.gradle @@ -7,6 +7,7 @@ dependencies { compile project(':spring-session-data-geode') compile "org.springframework:spring-web" + compile "org.springframework.data:spring-data-geode-test" compile "org.webjars:bootstrap" compile "org.webjars:webjars-taglib" compile jstlDependencies diff --git a/samples/javaconfig/gemfire-clientserver/src/main/java/sample/ClientConfig.java b/samples/javaconfig/gemfire-clientserver/src/main/java/sample/ClientConfig.java index 7709680..4d3286f 100644 --- a/samples/javaconfig/gemfire-clientserver/src/main/java/sample/ClientConfig.java +++ b/samples/javaconfig/gemfire-clientserver/src/main/java/sample/ClientConfig.java @@ -16,34 +16,17 @@ package sample; -import java.util.Collections; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; +import org.springframework.context.annotation.Import; import org.springframework.data.gemfire.config.annotation.ClientCacheApplication; -import org.springframework.data.gemfire.config.annotation.ClientCacheConfigurer; +import org.springframework.data.gemfire.tests.integration.config.SubscriptionEnabledClientServerIntegrationTestsConfiguration; import org.springframework.session.data.gemfire.config.annotation.web.http.EnableGemFireHttpSession; // tag::class[] @ClientCacheApplication(name = "SpringSessionDataGeodeClientJavaConfigSample", logLevel = "error", pingInterval = 5000L, readTimeout = 15000, retryAttempts = 1, subscriptionEnabled = true) // <1> @EnableGemFireHttpSession(maxInactiveIntervalInSeconds = 30, poolName = "DEFAULT") // <2> +@Import(SubscriptionEnabledClientServerIntegrationTestsConfiguration.class) // <3> public class ClientConfig extends IntegrationTestConfig { - // Required to resolve property placeholders in Spring @Value annotations. - @Bean - static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer() { - return new PropertySourcesPlaceholderConfigurer(); - } - - @Bean - ClientCacheConfigurer clientCacheServerPortConfigurer( - @Value("${spring.session.data.geode.cache.server.port:40404}") int port) { // <3> - - return (beanName, clientCacheFactoryBean) -> - clientCacheFactoryBean.setServers(Collections.singletonList( - newConnectionEndpoint("localhost", port))); - } } // end::class[] diff --git a/samples/javaconfig/gemfire-clientserver/src/main/java/sample/ServerConfig.java b/samples/javaconfig/gemfire-clientserver/src/main/java/sample/ServerConfig.java index 37d241c..3485293 100644 --- a/samples/javaconfig/gemfire-clientserver/src/main/java/sample/ServerConfig.java +++ b/samples/javaconfig/gemfire-clientserver/src/main/java/sample/ServerConfig.java @@ -18,17 +18,16 @@ package sample; import java.io.IOException; -import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; +import org.springframework.context.annotation.Import; import org.springframework.data.gemfire.config.annotation.CacheServerApplication; -import org.springframework.data.gemfire.config.annotation.CacheServerConfigurer; +import org.springframework.data.gemfire.tests.integration.config.ClientServerIntegrationTestsConfiguration; import org.springframework.session.data.gemfire.config.annotation.web.http.EnableGemFireHttpSession; // tag::class[] @CacheServerApplication(name = "SpringSessionSampleJavaConfigGemFireClientServer", logLevel = "error") // <1> @EnableGemFireHttpSession(maxInactiveIntervalInSeconds = 30) // <2> +@Import(ClientServerIntegrationTestsConfiguration.class) // <3> public class ServerConfig { @SuppressWarnings("resource") @@ -36,19 +35,5 @@ public class ServerConfig { new AnnotationConfigApplicationContext(ServerConfig.class).registerShutdownHook(); } - // Required to resolve property placeholders in Spring @Value annotations. - @Bean - static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer() { - return new PropertySourcesPlaceholderConfigurer(); - } - - @Bean - CacheServerConfigurer cacheServerPortConfigurer( - @Value("${spring.session.data.geode.cache.server.port:40404}") int port) { // <3> - - return (beanName, cacheServerFactoryBean) -> { - cacheServerFactoryBean.setPort(port); - }; - } } // end::class[]