【问题标题】:Spring Boot and Infinspan cache on JBossJBoss 上的 Spring Boot 和 Infinspan 缓存
【发布时间】:2017-03-07 14:12:10
【问题描述】:

我已经在集群中安装并运行了 JBoss 7。我正在开发一个 Spring Boot 1.3.2 应用程序。我在 domain.xml 中定义了以下 Infinispan 缓存:

           <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>

在 application.properties 文件中,我定义了以下内容:

spring.cache.type=infinispan

然后在我定义的缓存类上:

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

当我尝试在 JBoss 上部署应用程序时,我收到以下错误:

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

如何配置它才能正常工作?

【问题讨论】:

    标签: java spring spring-boot infinispan spring-cache


    【解决方案1】:

    好的,我按照this 教程解决了这个问题。

    这就是我所做的。

    我创建了缓存配置类,它将定义我在 JBoss 中配置的 CacheManager:

    @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;
            }
        }
    }
    

    我添加了以下依赖项:

    <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>
    

    并明确声明 Infinispan 依赖:

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

    【讨论】:

    • 在 SO 中,解释解决方案总是更好,而不仅仅是放置链接。
    • 谢谢,我编辑了帖子并添加了解释。
    猜你喜欢
    • 2016-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-05
    • 2016-10-13
    • 2017-07-30
    • 1970-01-01
    • 2020-03-16
    相关资源
    最近更新 更多