简体   繁体   中英

Spring Boot and Infinspan cache on JBoss

I have JBoss 7 installed and running in a cluster. I'm developing a Spring Boot 1.3.2 application. I defined a following Infinispan cache in domain.xml:

           <cache-container name="my-cache" default-cache="auth">
                <transport stack="tcp" lock-timeout="10000"/>
                <replicated-cache name="auth" mode="SYNC" batching="true">
                    <locking isolation="REPEATABLE_READ"/>
                    <transaction mode="NONE"/>
                    <eviction strategy="LRU" max-entries="100"/>
                    <expiration max-idle="300000"/>
                </replicated-cache>
            </cache-container>

In application.properties file I defined a following:

spring.cache.type=infinispan

And then on my cache class I defined:

@CacheConfig(cacheNames="java:jboss/infinispan/cache/my-cache/auth")

When I try to deploy the app on JBoss I get the following error:

Caused by: java.lang.IllegalArgumentException: No cache manager could be auto-configured, check your configuration (caching type is 'INFINISPAN'

How can I configure it to work properly?

OK, I followed this tutorial and solved the issue.

This is what I did.

I created cache config class which will define my CacheManager configured in JBoss:

@Configuration
@EnableCaching
public class CachingConfig {

    @Bean
    public CacheManager cacheManager() {
        JndiTemplate jndiTemplate = new JndiTemplate();
        try {
            EmbeddedCacheManager embededCacheManager = (EmbeddedCacheManager) jndiTemplate.lookup("java:jboss/infinispan/container/my-cache");
            SpringEmbeddedCacheManager cacheManager = new SpringEmbeddedCacheManager(embededCacheManager);
            return cacheManager;
        } catch (NamingException e) {
            e.printStackTrace();
            return null;
        }
    }
}

I added following dependencies:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
</dependency>
<dependency>
    <groupId>org.infinispan</groupId>
    <artifactId>infinispan-spring</artifactId>
    <version>5.1.2.FINAL</version>
</dependency>

And explicitly declared Infinispan dependency:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <archive>
            <manifestEntries>
                <Dependencies>org.infinispan</Dependencies>
            </manifestEntries>
        </archive>
    </configuration>
</plugin>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM