diff --git a/spring-boot-dependencies/pom.xml b/spring-boot-dependencies/pom.xml index 6d6f4fb0dd..1b5c41cb6f 100644 --- a/spring-boot-dependencies/pom.xml +++ b/spring-boot-dependencies/pom.xml @@ -71,7 +71,6 @@ 3.2.1 2.3.23 2.2.0 - 8.2.0 3.0.0 1.12 2.4.6 @@ -152,6 +151,7 @@ 1.0.3.RELEASE 2.0.9.RELEASE 1.1.0.RELEASE + 1.1.0.RELEASE 1.1.4.RELEASE 2.0.3.RELEASE 1.0.2.RELEASE @@ -669,17 +669,6 @@ jackson-module-parameter-names ${jackson.version} - - com.gemstone.gemfire - gemfire - ${gemfire.version} - - - org.springframework.data - spring-data-gemfire - - - com.github.ben-manes.caffeine caffeine @@ -2053,6 +2042,11 @@ spring-session-data-redis ${spring-session.version} + + org.springframework.shell + spring-shell + ${spring-shell.version} + org.springframework.social spring-social-config diff --git a/spring-boot-samples/spring-boot-sample-data-gemfire/pom.xml b/spring-boot-samples/spring-boot-sample-data-gemfire/pom.xml index 0072a4b964..0b77eb8c33 100644 --- a/spring-boot-samples/spring-boot-sample-data-gemfire/pom.xml +++ b/spring-boot-samples/spring-boot-sample-data-gemfire/pom.xml @@ -8,8 +8,8 @@ 1.4.0.BUILD-SNAPSHOT spring-boot-sample-data-gemfire - Spring Boot Data Gemfire Sample - Spring Boot Data Gemfire Sample + Spring Boot Data GemFire Sample + Spring Boot Data GemFire Sample http://projects.spring.io/spring-boot/ Pivotal Software, Inc. @@ -19,14 +19,23 @@ ${basedir}/../.. - - org.springframework.boot - spring-boot-starter - org.springframework.boot spring-boot-starter-data-gemfire + + + org.springframework.shell + spring-shell + runtime + + + + org.springframework.boot + spring-boot-configuration-processor + true + + org.springframework.boot spring-boot-starter-test diff --git a/spring-boot-samples/spring-boot-sample-data-gemfire/src/main/java/sample/data/gemfire/SampleDataGemFireApplication.java b/spring-boot-samples/spring-boot-sample-data-gemfire/src/main/java/sample/data/gemfire/SampleDataGemFireApplication.java index 2fdbc4bdb8..9c33171a79 100644 --- a/spring-boot-samples/spring-boot-sample-data-gemfire/src/main/java/sample/data/gemfire/SampleDataGemFireApplication.java +++ b/spring-boot-samples/spring-boot-sample-data-gemfire/src/main/java/sample/data/gemfire/SampleDataGemFireApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013 the original author or authors. + * Copyright 2012-2016 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. @@ -16,9 +16,21 @@ package sample.data.gemfire; +import java.util.Properties; + +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.RegionAttributes; +import sample.data.gemfire.config.SampleDataGemFireProperties; +import sample.data.gemfire.domain.Gemstone; + import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.ImportResource; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.data.gemfire.CacheFactoryBean; +import org.springframework.data.gemfire.GemfireTransactionManager; +import org.springframework.data.gemfire.RegionAttributesFactoryBean; +import org.springframework.data.gemfire.ReplicatedRegionFactoryBean; import org.springframework.data.gemfire.repository.config.EnableGemfireRepositories; import org.springframework.transaction.annotation.EnableTransactionManagement; @@ -30,13 +42,76 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; * @author John Blum */ @SpringBootApplication -@ImportResource("/spring-data-gemfire-cache.xml") @EnableGemfireRepositories @EnableTransactionManagement +@EnableConfigurationProperties(SampleDataGemFireProperties.class) public class SampleDataGemFireApplication { + protected static final String GEMSTONES_REGION_NAME = "Gemstones"; + + private final SampleDataGemFireProperties applicationProperties; + + public SampleDataGemFireApplication(SampleDataGemFireProperties applicationProperties) { + this.applicationProperties = applicationProperties; + } + public static void main(final String[] args) { SpringApplication.run(SampleDataGemFireApplication.class, args); } + + @Bean + CacheFactoryBean gemfireCache() { + CacheFactoryBean gemfireCache = new CacheFactoryBean(); + + gemfireCache.setClose(true); + gemfireCache.setProperties(gemfireProperties()); + + return gemfireCache; + } + + private Properties gemfireProperties() { + Properties gemfireProperties = new Properties(); + + gemfireProperties.setProperty("name", SampleDataGemFireApplication.class.getSimpleName()); + gemfireProperties.setProperty("mcast-port", "0"); + gemfireProperties.setProperty("locators", ""); + gemfireProperties.setProperty("log-level", this.applicationProperties.getLogLevel()); + + return gemfireProperties; + } + + @Bean(name = GEMSTONES_REGION_NAME) + ReplicatedRegionFactoryBean gemstonesRegion(Cache gemfireCache, + RegionAttributes gemstonesRegionAttributes) { + + ReplicatedRegionFactoryBean gemstonesRegion = + new ReplicatedRegionFactoryBean(); + + gemstonesRegion.setAttributes(gemstonesRegionAttributes); + gemstonesRegion.setClose(false); + gemstonesRegion.setCache(gemfireCache); + gemstonesRegion.setName(GEMSTONES_REGION_NAME); + gemstonesRegion.setPersistent(false); + + return gemstonesRegion; + } + + @Bean + @SuppressWarnings("unchecked") + RegionAttributesFactoryBean gemstonesRegionAttributes() { + RegionAttributesFactoryBean gemstonesRegionAttributes = + new RegionAttributesFactoryBean(); + + gemstonesRegionAttributes.setKeyConstraint(Long.class); + gemstonesRegionAttributes.setValueConstraint(Gemstone.class); + + return gemstonesRegionAttributes; + } + + @Bean + GemfireTransactionManager gemfireTransactionManager(Cache gemfireCache) { + return new GemfireTransactionManager(gemfireCache); + } + } diff --git a/spring-boot-samples/spring-boot-sample-data-gemfire/src/main/java/sample/data/gemfire/config/SampleDataGemFireProperties.java b/spring-boot-samples/spring-boot-sample-data-gemfire/src/main/java/sample/data/gemfire/config/SampleDataGemFireProperties.java new file mode 100644 index 0000000000..964330d070 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-data-gemfire/src/main/java/sample/data/gemfire/config/SampleDataGemFireProperties.java @@ -0,0 +1,42 @@ +/* + * Copyright 2012-2016 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.data.gemfire.config; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * Configuration properties for Gemfire sample. + * + * @author John Blum + */ +@ConfigurationProperties(prefix = "sample.data.gemfire") +public class SampleDataGemFireProperties { + + /** + * Caching log level. + */ + private String logLevel = "config"; + + public String getLogLevel() { + return this.logLevel; + } + + public void setLogLevel(String logLevel) { + this.logLevel = logLevel; + } + +} diff --git a/spring-boot-samples/spring-boot-sample-data-gemfire/src/main/java/sample/data/gemfire/domain/Gemstone.java b/spring-boot-samples/spring-boot-sample-data-gemfire/src/main/java/sample/data/gemfire/domain/Gemstone.java index 2303ac0110..c883476817 100644 --- a/spring-boot-samples/spring-boot-sample-data-gemfire/src/main/java/sample/data/gemfire/domain/Gemstone.java +++ b/spring-boot-samples/spring-boot-sample-data-gemfire/src/main/java/sample/data/gemfire/domain/Gemstone.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013 the original author or authors. + * Copyright 2012-2016 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. @@ -89,7 +89,7 @@ public class Gemstone implements Serializable { @Override public String toString() { return String.format("{ @type = %1$s, id = %2$d, name = %3$s }", - getClass().getName(), getId(), getName()); + getClass().getName(), getId(), getName()); } } diff --git a/spring-boot-samples/spring-boot-sample-data-gemfire/src/main/java/sample/data/gemfire/service/GemstoneServiceImpl.java b/spring-boot-samples/spring-boot-sample-data-gemfire/src/main/java/sample/data/gemfire/service/GemstoneServiceImpl.java index e0c9f4021b..a16d9fa8ed 100644 --- a/spring-boot-samples/spring-boot-sample-data-gemfire/src/main/java/sample/data/gemfire/service/GemstoneServiceImpl.java +++ b/spring-boot-samples/spring-boot-sample-data-gemfire/src/main/java/sample/data/gemfire/service/GemstoneServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 the original author or authors. + * Copyright 2012-2016 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. @@ -43,14 +43,15 @@ public class GemstoneServiceImpl implements GemstoneService { Arrays.asList("ALEXANDRITE", "AQUAMARINE", "DIAMOND", "OPAL", "PEARL", "RUBY", "SAPPHIRE", "SPINEL", "TOPAZ")); - @Autowired - private GemstoneRepository gemstoneRepo; + private final GemstoneRepository gemstoneRepository; + + public GemstoneServiceImpl(GemstoneRepository gemstoneRepository) { + this.gemstoneRepository = gemstoneRepository; + } @PostConstruct public void init() { - Assert.notNull(this.gemstoneRepo, - "A reference to the 'GemstoneRepository' was not properly configured!"); - System.out.printf("%1$s initialized!%n", getClass().getSimpleName()); + System.out.printf("[%1$s] initialized!%n", getClass().getSimpleName()); } /** @@ -62,7 +63,7 @@ public class GemstoneServiceImpl implements GemstoneService { @Override @Transactional(readOnly = true) public long count() { - return this.gemstoneRepo.count(); + return this.gemstoneRepository.count(); } /** @@ -75,8 +76,8 @@ public class GemstoneServiceImpl implements GemstoneService { */ @Override @Transactional(readOnly = true) - public Gemstone get(final Long id) { - return this.gemstoneRepo.findOne(id); + public Gemstone get(Long id) { + return this.gemstoneRepository.findOne(id); } /** @@ -89,8 +90,8 @@ public class GemstoneServiceImpl implements GemstoneService { */ @Override @Transactional(readOnly = true) - public Gemstone get(final String name) { - return this.gemstoneRepo.findByName(name); + public Gemstone get(String name) { + return this.gemstoneRepository.findByName(name); } /** @@ -105,7 +106,7 @@ public class GemstoneServiceImpl implements GemstoneService { @Override @Transactional(readOnly = true) public Iterable list() { - return this.gemstoneRepo.findAll(); + return this.gemstoneRepository.findAll(); } /** @@ -118,32 +119,30 @@ public class GemstoneServiceImpl implements GemstoneService { */ @Override @Transactional - public Gemstone save(final Gemstone gemstone) { + public Gemstone save(Gemstone gemstone) { Assert.notNull(gemstone, "The Gemstone to save must not be null!"); Assert.notNull(gemstone.getName(), "The name of the Gemstone must be specified!"); - // NOTE deliberately (naively) validate the Gemstone after mutating data access in - // GemFire rather than before - // to demonstrate transactions in GemFire. - Gemstone savedGemstone = validate(this.gemstoneRepo.save(gemstone)); + // NOTE deliberately (& naively) validate the Gemstone after mutating data access in + // GemFire rather than before to demonstrate transactions in GemFire. + Gemstone savedGemstone = validate(this.gemstoneRepository.save(gemstone)); - Assert.state(savedGemstone.equals(get(gemstone.getId())), - String.format( - "Failed to find Gemstone (%1$s) in GemFire's Cache Region 'Gemstones'!", - gemstone)); + Assert.state(savedGemstone.equals(get(gemstone.getId())), String.format( + "Failed to find Gemstone (%1$s) in GemFire's Cache Region 'Gemstones'!", + gemstone)); - System.out.printf("Saved Gemstone (%1$s)%n", savedGemstone.getName()); + System.out.printf("Saved Gemstone [%1$s]%n", savedGemstone.getName()); return gemstone; } - private Gemstone validate(final Gemstone gemstone) { + Gemstone validate(Gemstone gemstone) { if (!APPROVED_GEMS.contains(gemstone.getName().toUpperCase())) { - // NOTE if the Gemstone is not valid, blow chunks (should cause transaction to - // rollback in GemFire)! - System.err.printf("Illegal Gemstone (%1$s)!%n", gemstone.getName()); + // NOTE if the Gemstone is not valid, throw error... + // Should cause transaction to rollback in GemFire! + System.err.printf("Illegal Gemstone [%1$s]!%n", gemstone.getName()); throw new IllegalGemstoneException( - String.format("'%1$s' is not a valid Gemstone!", gemstone.getName())); + String.format("[%1$s] is not a valid Gemstone!", gemstone.getName())); } return gemstone; @@ -151,21 +150,10 @@ public class GemstoneServiceImpl implements GemstoneService { public static final class IllegalGemstoneException extends IllegalArgumentException { - public IllegalGemstoneException() { - } - - public IllegalGemstoneException(final String message) { + public IllegalGemstoneException(String message) { super(message); } - public IllegalGemstoneException(final Throwable cause) { - super(cause); - } - - public IllegalGemstoneException(final String message, final Throwable cause) { - super(message, cause); - } - } } diff --git a/spring-boot-samples/spring-boot-sample-data-gemfire/src/main/resources/spring-data-gemfire-cache.xml b/spring-boot-samples/spring-boot-sample-data-gemfire/src/main/resources/spring-data-gemfire-cache.xml deleted file mode 100644 index 82da83da84..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-gemfire/src/main/resources/spring-data-gemfire-cache.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - GemstonesSpringGemFireApp - config - 0 - - - - - - - - - diff --git a/spring-boot-samples/spring-boot-sample-data-gemfire/src/test/java/sample/data/gemfire/SampleDataGemFireApplicationTests.java b/spring-boot-samples/spring-boot-sample-data-gemfire/src/test/java/sample/data/gemfire/SampleDataGemFireApplicationTests.java index bf1f2e3252..38aed96983 100644 --- a/spring-boot-samples/spring-boot-sample-data-gemfire/src/test/java/sample/data/gemfire/SampleDataGemFireApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-data-gemfire/src/test/java/sample/data/gemfire/SampleDataGemFireApplicationTests.java @@ -18,7 +18,6 @@ package sample.data.gemfire; import java.util.concurrent.atomic.AtomicLong; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import sample.data.gemfire.domain.Gemstone; @@ -32,8 +31,7 @@ import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; /** - * The SampleDataGemFireApplicationTests class is a test suite with test cases testing the - * SampleDataGemFireApplication in Spring Boot. + * Tests for {@link SampleDataGemFireApplication}. * * @author John Blum */ @@ -44,15 +42,10 @@ public class SampleDataGemFireApplicationTests { @Autowired private GemstoneService gemstoneService; - private final AtomicLong ID_GENERATOR = new AtomicLong(0l); - - @Before - public void setup() { - assertThat(this.gemstoneService).isNotNull(); - } + private final AtomicLong idGenerator = new AtomicLong(0L); @Test - public void testGemstonesApp() { + public void gemstonesAppServiceEndpoints() { assertThat(this.gemstoneService.count()).isEqualTo(0); assertThat(this.gemstoneService.list()).isEmpty(); @@ -60,37 +53,41 @@ public class SampleDataGemFireApplicationTests { this.gemstoneService.save(createGemstone("Ruby")); assertThat(this.gemstoneService.count()).isEqualTo(2); - assertThat(this.gemstoneService.list()).contains(getGemstones("Diamond", "Ruby")); + assertThat(this.gemstoneService.list()).contains( + getGemstones("Diamond", "Ruby")); try { this.gemstoneService.save(createGemstone("Coal")); } - catch (IllegalGemstoneException ex) { - // Expected + catch (IllegalGemstoneException ignore) { + // expected } assertThat(this.gemstoneService.count()).isEqualTo(2); - assertThat(this.gemstoneService.list()).contains(getGemstones("Diamond", "Ruby")); + assertThat(this.gemstoneService.list()).contains( + getGemstones("Diamond", "Ruby")); this.gemstoneService.save(createGemstone("Pearl")); this.gemstoneService.save(createGemstone("Sapphire")); assertThat(this.gemstoneService.count()).isEqualTo(4); - assertThat(this.gemstoneService.list()) - .contains(getGemstones("Diamond", "Ruby", "Pearl", "Sapphire")); + assertThat(this.gemstoneService.list()).contains( + getGemstones("Diamond", "Ruby", "Pearl", "Sapphire")); try { this.gemstoneService.save(createGemstone("Quartz")); } - catch (IllegalGemstoneException expected) { + catch (IllegalGemstoneException ignore) { + // expected } assertThat(this.gemstoneService.count()).isEqualTo(4); - assertThat(this.gemstoneService.list()) - .contains(getGemstones("Diamond", "Ruby", "Pearl", "Sapphire")); - assertThat(this.gemstoneService.get("Diamond")) - .isEqualTo(createGemstone("Diamond")); - assertThat(this.gemstoneService.get("Pearl")).isEqualTo(createGemstone("Pearl")); + assertThat(this.gemstoneService.list()).contains( + getGemstones("Diamond", "Ruby", "Pearl", "Sapphire")); + assertThat(this.gemstoneService.get("Diamond")).isEqualTo( + createGemstone("Diamond")); + assertThat(this.gemstoneService.get("Pearl")).isEqualTo( + createGemstone("Pearl")); } private Gemstone[] getGemstones(String... names) { @@ -102,7 +99,7 @@ public class SampleDataGemFireApplicationTests { } private Gemstone createGemstone(String name) { - return createGemstone(this.ID_GENERATOR.incrementAndGet(), name); + return createGemstone(this.idGenerator.incrementAndGet(), name); } private Gemstone createGemstone(Long id, String name) { diff --git a/spring-boot-starters/spring-boot-starter-data-gemfire/pom.xml b/spring-boot-starters/spring-boot-starter-data-gemfire/pom.xml index bd56d65877..67b6860675 100644 --- a/spring-boot-starters/spring-boot-starter-data-gemfire/pom.xml +++ b/spring-boot-starters/spring-boot-starter-data-gemfire/pom.xml @@ -24,8 +24,8 @@ spring-boot-starter - com.gemstone.gemfire - gemfire + org.springframework.data + spring-data-gemfire commons-logging @@ -33,14 +33,6 @@ - - org.springframework.data - spring-data-gemfire - - - org.aspectj - aspectjweaver - diff --git a/spring-boot-starters/spring-boot-starter-data-gemfire/src/main/resources/META-INF/spring.provides b/spring-boot-starters/spring-boot-starter-data-gemfire/src/main/resources/META-INF/spring.provides index 52b4808d1d..6788816558 100644 --- a/spring-boot-starters/spring-boot-starter-data-gemfire/src/main/resources/META-INF/spring.provides +++ b/spring-boot-starters/spring-boot-starter-data-gemfire/src/main/resources/META-INF/spring.provides @@ -1 +1 @@ -provides: gemfire,spring-data-gemfire +provides: spring-data-gemfire