Skip to content

Commit 31eac01

Browse files
committed
Improve spring-boot-sample-cache UX by using Maven profiles
Fixes gh-8202
1 parent 87b8ce6 commit 31eac01

File tree

2 files changed

+117
-72
lines changed

2 files changed

+117
-72
lines changed

spring-boot-samples/spring-boot-sample-cache/README.adoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ used to configure the underlying `CacheManager`. Note that EhCache 3 uses a diff
6464
format and doesn't default to `ehcache.xml` anymore. Check
6565
http://www.ehcache.org/documentation/3.0/xml.html[the documentation] for more details.
6666

67+
Run sample cache application using EhCache with `$mvn -P ehcache spring-boot:run`
6768

6869

6970
=== Hazelcast
@@ -72,6 +73,7 @@ the project to enable support for Hazelcast. Since there is a default `hazelcas
7273
configuration file at the root of the classpath, it is used to automatically configure
7374
the underlying `HazelcastInstance`.
7475

76+
Run sample cache application using Hazelcast with `$mvn -P hazelcast spring-boot:run`
7577

7678

7779
=== Infinispan
@@ -81,29 +83,35 @@ so if you don't specify anything it will bootstrap on a hardcoded default. You c
8183
the `spring.cache.infinispan.config` property to use the provided `infinispan.xml`
8284
configuration instead.
8385

86+
Run sample cache application using Infinispan with `$mvn -P infinispan spring-boot:run`
8487

8588

8689
=== Couchbase
8790
Add the `java-client` and `couchbase-spring-cache` dependencies and make sure that you
8891
have setup at least a `spring.couchbase.bootstrap-hosts` property.
8992

93+
Start a Couchbase server, then run the sample cache application using Couchbase with `$mvn -P couchbase spring-boot:run`
9094

9195

9296
=== Redis
9397
Add the `spring-boot-starter-data-redis` and make sure it is configured properly (by default,
9498
a redis instance with the default settings is expected on your local box).
9599

100+
Start a Redis server, then run the sample cache application using Redis with `$mvn -P redis spring-boot:run`
96101

97102

98103
=== Caffeine
99104
Simply add the `com.github.ben-manes.caffeine:caffeine` dependency to enable support
100105
for Caffeine. You can customize how caches are created in different ways, see
101106
`application.properties` for an example and the documentation for more details.
102107

108+
Run sample cache application using Caffeine with `$mvn -P caffeine spring-boot:run`
103109

104110

105111
=== Guava
106112
Spring Boot does not provide any dependency management for _Guava_ so you'll have to add
107113
the `com.google.guava:guava` dependency with a version. You can customize how caches are
108114
created in different ways, see `application.properties` for an example and the
109115
documentation for more details.
116+
117+
Run sample cache application using Guava with `$mvn -P guava spring-boot:run`

spring-boot-samples/spring-boot-sample-cache/pom.xml

Lines changed: 109 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -33,78 +33,6 @@
3333
<groupId>org.springframework.boot</groupId>
3434
<artifactId>spring-boot-starter-actuator</artifactId>
3535
</dependency>
36-
37-
<!-- JSR-107 API (uncomment to try the JCache support) -->
38-
<!--
39-
<dependency>
40-
<groupId>javax.cache</groupId>
41-
<artifactId>cache-api</artifactId>
42-
</dependency>
43-
-->
44-
45-
<!-- Additional cache providers (uncomment to try them) -->
46-
<!--
47-
<dependency>
48-
<groupId>net.sf.ehcache</groupId>
49-
<artifactId>ehcache</artifactId>
50-
</dependency>
51-
-->
52-
<!--
53-
<dependency>
54-
<groupId>org.ehcache</groupId>
55-
<artifactId>ehcache</artifactId>
56-
</dependency>
57-
-->
58-
<!--
59-
<dependency>
60-
<groupId>com.hazelcast</groupId>
61-
<artifactId>hazelcast</artifactId>
62-
</dependency>
63-
<dependency>
64-
<groupId>com.hazelcast</groupId>
65-
<artifactId>hazelcast-spring</artifactId>
66-
</dependency>
67-
-->
68-
<!--
69-
<dependency>
70-
<groupId>org.infinispan</groupId>
71-
<artifactId>infinispan-spring4-embedded</artifactId>
72-
</dependency>
73-
<dependency>
74-
<groupId>org.infinispan</groupId>
75-
<artifactId>infinispan-jcache</artifactId>
76-
</dependency>
77-
-->
78-
<!--
79-
<dependency>
80-
<groupId>com.couchbase.client</groupId>
81-
<artifactId>java-client</artifactId>
82-
</dependency>
83-
<dependency>
84-
<groupId>com.couchbase.client</groupId>
85-
<artifactId>couchbase-spring-cache</artifactId>
86-
</dependency>
87-
-->
88-
<!--
89-
<dependency>
90-
<groupId>org.springframework.boot</groupId>
91-
<artifactId>spring-boot-starter-data-redis</artifactId>
92-
</dependency>
93-
-->
94-
<!--
95-
<dependency>
96-
<groupId>com.github.ben-manes.caffeine</groupId>
97-
<artifactId>caffeine</artifactId>
98-
</dependency>
99-
-->
100-
<!--
101-
<dependency>
102-
<groupId>com.google.guava</groupId>
103-
<artifactId>guava</artifactId>
104-
<version>18.0</version>
105-
</dependency>
106-
-->
107-
10836
<!-- Test -->
10937
<dependency>
11038
<groupId>org.springframework.boot</groupId>
@@ -120,4 +48,113 @@
12048
</plugin>
12149
</plugins>
12250
</build>
51+
<profiles>
52+
<!-- JCache API (JSR-107 support) -->
53+
<!-- Include with any of the caching providers below using, e.g. `$mvn -P jcache,hazelcast spring-boot:run` -->
54+
<profile>
55+
<id>jcache</id>
56+
<dependencies>
57+
<dependency>
58+
<groupId>javax.cache</groupId>
59+
<artifactId>cache-api</artifactId>
60+
</dependency>
61+
</dependencies>
62+
</profile>
63+
<!-- mvn -P caffeine spring-boot:run -->
64+
<profile>
65+
<id>caffeine</id>
66+
<dependencies>
67+
<dependency>
68+
<groupId>com.github.ben-manes.caffeine</groupId>
69+
<artifactId>caffeine</artifactId>
70+
</dependency>
71+
</dependencies>
72+
</profile>
73+
<!-- Start Couchbase server, then... -->
74+
<!-- mvn -P couchbase spring-boot:run -->
75+
<profile>
76+
<id>couchbase</id>
77+
<dependencies>
78+
<dependency>
79+
<groupId>com.couchbase.client</groupId>
80+
<artifactId>java-client</artifactId>
81+
</dependency>
82+
<dependency>
83+
<groupId>com.couchbase.client</groupId>
84+
<artifactId>couchbase-spring-cache</artifactId>
85+
</dependency>
86+
</dependencies>
87+
</profile>
88+
<!-- mvn -P ehcache spring-boot:run -->
89+
<profile>
90+
<id>ehcache</id>
91+
<dependencies>
92+
<dependency>
93+
<groupId>net.sf.ehcache</groupId>
94+
<artifactId>ehcache</artifactId>
95+
</dependency>
96+
</dependencies>
97+
</profile>
98+
<!-- Start a Ehcache server, then... -->
99+
<!-- mvn -P org-ehcache spring-boot:run -->
100+
<profile>
101+
<id>org-ehcache</id>
102+
<dependencies>
103+
<dependency>
104+
<groupId>org.ehcache</groupId>
105+
<artifactId>ehcache</artifactId>
106+
</dependency>
107+
</dependencies>
108+
</profile>
109+
<!-- mvn -P guava spring-boot:run -->
110+
<profile>
111+
<id>guava</id>
112+
<dependencies>
113+
<dependency>
114+
<groupId>com.google.guava</groupId>
115+
<artifactId>guava</artifactId>
116+
<version>18.0</version>
117+
</dependency>
118+
</dependencies>
119+
</profile>
120+
<!-- mvn -P hazelcast spring-boot:run -->
121+
<profile>
122+
<id>hazelcast</id>
123+
<dependencies>
124+
<dependency>
125+
<groupId>com.hazelcast</groupId>
126+
<artifactId>hazelcast</artifactId>
127+
</dependency>
128+
<dependency>
129+
<groupId>com.hazelcast</groupId>
130+
<artifactId>hazelcast-spring</artifactId>
131+
</dependency>
132+
</dependencies>
133+
</profile>
134+
<!-- mvn -P infinispan spring-boot:run -->
135+
<profile>
136+
<id>infinispan</id>
137+
<dependencies>
138+
<dependency>
139+
<groupId>org.infinispan</groupId>
140+
<artifactId>infinispan-spring4-embedded</artifactId>
141+
</dependency>
142+
<dependency>
143+
<groupId>org.infinispan</groupId>
144+
<artifactId>infinispan-jcache</artifactId>
145+
</dependency>
146+
</dependencies>
147+
</profile>
148+
<!-- Start a Redis Server ($. <redis-install>/src/redis-server), then... -->
149+
<!-- mvn -P redis spring-boot:run -->
150+
<profile>
151+
<id>redis</id>
152+
<dependencies>
153+
<dependency>
154+
<groupId>org.springframework.boot</groupId>
155+
<artifactId>spring-boot-starter-data-redis</artifactId>
156+
</dependency>
157+
</dependencies>
158+
</profile>
159+
</profiles>
123160
</project>

0 commit comments

Comments
 (0)