Skip to content

Instantly share code, notes, and snippets.

@Component
@Service
public class CacheServiceImpl implements CacheService {
@Activate
void onActivate() {
URL url = getClass().getResource("/ehcache.xml");
cacheManager = CacheManager.create(url);
registerMBeans();
cacheManager.clearAll();
@Component
@Service
public class SimpleDepartmentService implements DepartmentService {
/**
* Cache service.
*/
@Reference
private CacheService cacheService;
/**
@Component
@Service
public class CacheServiceImpl implements CacheService {
@Override
public void addToCache(final String cacheName, final String itemId, final Object item) {
// Do not save any null key or item
if (!contains(itemId, "null") && item != null) {
Ehcache cache = cacheManager.getEhcache(cacheName);
if (cache != null) {
Element element = new Element(itemId, item);
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true"
monitoring="autodetect" dynamicConfig="true">
<!-- Sample cache named cache1
This cache contains a maximum in memory of 10000 elements, and will expire
an element if it is idle for more than 5 minutes and lives for more than
10 minutes.
If there are more than 10000 elements it will overflow to the
<build>
<plugins>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<Embed-Dependency>
………,ehcache</Embed-Dependency>
</plugins>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.10.2.2.21</version>
</dependency>
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.ehcache</artifactId>
<version>2.6.5_1</version>
<scope>provided</scope>
$(function () {
var url = window.location.protocol + "//" + window.location.host;
if (window.location.pathname.indexOf('/api') > 0) {
url += window.location.pathname.substring(0, window.location.pathname.indexOf('/api'))
}
url += "/api-docs";
log('API URL: ' + apiUrl);
window.swaggerUi = new SwaggerUi({})
@atishn
atishn / Controller.java
Created July 22, 2015 02:11
Sample Controller
@RequestMapping(value = “/product”, produces = “application/json”)
@ResponseBody
@ApiOperation(value = "Product List", notes = "List by Category")
final ProductList getProducts()
import com.mangofactory.swagger.configuration.SpringSwaggerConfig;
import com.mangofactory.swagger.plugin.EnableSwagger;
import com.mangofactory.swagger.plugin.SwaggerSpringMvcPlugin;
import com.wordnik.swagger.model.ApiInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.List;
@atishn
atishn / pom.xml
Created July 22, 2015 01:46
Swagger POM
<dependency>
<groupId>com.mangofactory</groupId>
<artifactId>swagger-springmvc</artifactId>
<version>0.9.1</version>
</dependency>