Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
23a27845
Commit
23a27845
authored
Mar 28, 2015
by
Eddú Meléndez
Committed by
Stephane Nicoll
Jun 01, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add cache sample
See gh-2633
parent
91ce0abe
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
309 additions
and
0 deletions
+309
-0
README.adoc
spring-boot-samples/README.adoc
+2
-0
pom.xml
spring-boot-samples/pom.xml
+1
-0
pom.xml
spring-boot-samples/spring-boot-sample-cache/pom.xml
+48
-0
CountryService.java
...oot-sample-cache/src/main/java/sample/CountryService.java
+38
-0
SampleEhCacheCacheApplication.java
...e/src/main/java/sample/SampleEhCacheCacheApplication.java
+35
-0
Startup.java
...pring-boot-sample-cache/src/main/java/sample/Startup.java
+41
-0
application-override.properties
...-cache/src/main/resources/application-override.properties
+1
-0
ehcache-override.xml
...ample-cache/src/main/resources/cache/ehcache-override.xml
+8
-0
ehcache.xml
...s/spring-boot-sample-cache/src/main/resources/ehcache.xml
+8
-0
AbstractEhCacheCacheTests.java
...cache/src/test/java/sample/AbstractEhCacheCacheTests.java
+63
-0
SampleEhCacheCacheApplicationOverrideTests.java
...va/sample/SampleEhCacheCacheApplicationOverrideTests.java
+33
-0
SampleEhCacheCacheApplicationTests.java
.../test/java/sample/SampleEhCacheCacheApplicationTests.java
+31
-0
No files found.
spring-boot-samples/README.adoc
View file @
23a27845
...
...
@@ -16,6 +16,8 @@
-- A production features sample with no web application
* link:spring-boot-sample-actuator-log4j[spring-boot-sample-actuator-log4j]
-- A production features sample using log4j for logging (instead of logback)
* link:spring-boot-sample-cache-ehcache[spring-boot-sample-cache]
-- A web sample that uses Spring's cache abstraction
* link:spring-boot-sample-web-ui[spring-boot-sample-web-ui]
-- A thymeleaf web application
* link:spring-boot-sample-web-static[spring-boot-sample-web-static]
...
...
spring-boot-samples/pom.xml
View file @
23a27845
...
...
@@ -30,6 +30,7 @@
<module>
spring-boot-sample-aop
</module>
<module>
spring-boot-sample-atmosphere
</module>
<module>
spring-boot-sample-batch
</module>
<module>
spring-boot-sample-cache
</module>
<module>
spring-boot-sample-data-elasticsearch
</module>
<module>
spring-boot-sample-data-gemfire
</module>
<module>
spring-boot-sample-data-jpa
</module>
...
...
spring-boot-samples/spring-boot-sample-cache/pom.xml
0 → 100644
View file @
23a27845
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<!-- Your own application should inherit from spring-boot-starter-parent -->
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-samples
</artifactId>
<version>
1.3.0.BUILD-SNAPSHOT
</version>
</parent>
<artifactId>
spring-boot-sample-cache
</artifactId>
<name>
Spring Boot Cache Sample
</name>
<description>
Spring Boot Cache Sample
</description>
<url>
http://projects.spring.io/spring-boot/
</url>
<organization>
<name>
Pivotal Software, Inc.
</name>
<url>
http://www.spring.io
</url>
</organization>
<properties>
<main.basedir>
${basedir}/../..
</main.basedir>
</properties>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-context-support
</artifactId>
</dependency>
<dependency>
<groupId>
net.sf.ehcache
</groupId>
<artifactId>
ehcache
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
</plugin>
</plugins>
</build>
</project>
spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/CountryService.java
0 → 100644
View file @
23a27845
/*
* Copyright 2012-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
sample
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.stereotype.Component
;
import
java.util.Arrays
;
import
java.util.List
;
/**
* @author Eddú Meléndez
* @since 1.3.0
*/
@Component
public
class
CountryService
{
@Cacheable
(
"countries"
)
public
List
<
String
>
countries
()
{
System
.
out
.
println
(
"Loading countries"
);
return
Arrays
.
asList
(
"Perú"
,
"United States"
);
}
}
spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/SampleEhCacheCacheApplication.java
0 → 100644
View file @
23a27845
/*
* Copyright 2012-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
sample
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.cache.annotation.EnableCaching
;
/**
* @author Eddú Meléndez
* @since 1.3.0
*/
@EnableCaching
@SpringBootApplication
public
class
SampleEhCacheCacheApplication
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
SampleEhCacheCacheApplication
.
class
);
}
}
spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/Startup.java
0 → 100644
View file @
23a27845
/*
* Copyright 2012-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
sample
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.CommandLineRunner
;
import
org.springframework.stereotype.Component
;
/**
* @author Eddú Meléndez
* @since 1.3.0
*/
@Component
public
class
Startup
implements
CommandLineRunner
{
@Autowired
private
CountryService
countryService
;
@Override
public
void
run
(
String
...
args
)
throws
Exception
{
System
.
out
.
println
(
"---- calling country service"
);
System
.
out
.
println
(
countryService
.
countries
());
System
.
out
.
println
(
"---- calling country service again from cache."
);
System
.
out
.
println
(
countryService
.
countries
());
}
}
spring-boot-samples/spring-boot-sample-cache/src/main/resources/application-override.properties
0 → 100644
View file @
23a27845
spring.cache.config
=
/cache/ehcache-override.xml
spring-boot-samples/spring-boot-sample-cache/src/main/resources/cache/ehcache-override.xml
0 → 100644
View file @
23a27845
<ehcache
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation=
"ehcache.xsd"
updateCheck=
"true"
monitoring=
"autodetect"
dynamicConfig=
"true"
>
<cache
name=
"countries"
maxBytesLocalHeap=
"50m"
timeToLiveSeconds=
"100"
>
</cache>
</ehcache>
spring-boot-samples/spring-boot-sample-cache/src/main/resources/ehcache.xml
0 → 100644
View file @
23a27845
<ehcache
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation=
"ehcache.xsd"
updateCheck=
"true"
monitoring=
"autodetect"
dynamicConfig=
"true"
>
<cache
name=
"countries"
maxBytesLocalHeap=
"50m"
timeToLiveSeconds=
"100"
>
</cache>
</ehcache>
spring-boot-samples/spring-boot-sample-cache/src/test/java/sample/AbstractEhCacheCacheTests.java
0 → 100644
View file @
23a27845
/*
* Copyright 2012-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
sample
;
import
org.junit.After
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.cache.CacheManager
;
import
org.springframework.cache.ehcache.EhCacheCacheManager
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
hamcrest
.
Matchers
.
contains
;
import
static
org
.
hamcrest
.
core
.
IsInstanceOf
.
instanceOf
;
import
static
org
.
junit
.
Assert
.
assertThat
;
/**
* @author Eddú Meléndez
* @since 1.3.0
*/
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
{
SampleEhCacheCacheApplication
.
class
})
public
abstract
class
AbstractEhCacheCacheTests
{
@Autowired
private
CacheManager
cacheManager
;
@Autowired
private
EhCacheCacheManager
ehCacheManager
;
@After
public
void
tearDown
()
{
if
(
this
.
ehCacheManager
!=
null
)
{
this
.
ehCacheManager
.
getCacheManager
().
shutdown
();
}
}
@Test
public
void
testCacheManagerInstance
()
{
assertThat
(
this
.
cacheManager
,
instanceOf
(
EhCacheCacheManager
.
class
));
}
@Test
public
void
testCacheManager
()
{
assertThat
(
this
.
cacheManager
.
getCacheNames
(),
contains
(
"countries"
));
}
}
spring-boot-samples/spring-boot-sample-cache/src/test/java/sample/SampleEhCacheCacheApplicationOverrideTests.java
0 → 100644
View file @
23a27845
/*
* Copyright 2012-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
sample
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.test.context.ActiveProfiles
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
/**
* @author Eddú Meléndez
* @since 1.3.0
*/
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
{
SampleEhCacheCacheApplication
.
class
})
@ActiveProfiles
(
"override"
)
public
class
SampleEhCacheCacheApplicationOverrideTests
extends
AbstractEhCacheCacheTests
{
}
spring-boot-samples/spring-boot-sample-cache/src/test/java/sample/SampleEhCacheCacheApplicationTests.java
0 → 100644
View file @
23a27845
/*
* Copyright 2012-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
sample
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
/**
* @author Eddú Meléndez
* @since 1.3.0
*/
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
{
SampleEhCacheCacheApplication
.
class
})
public
class
SampleEhCacheCacheApplicationTests
extends
AbstractEhCacheCacheTests
{
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment