2

我的 DAO 层采用了一种昂贵的方法,如下所示:

@Component
@CacheConfig(cacheNames = {"userStories"})
public class UserStoryDaoImpl implements IUserStoryDao {

@Override
@Cacheable
public List<UserStory> getUserStoriesForProjectAndRelease(UserDto userDto, Set<Integer> 
reportProjectId, int releaseId) {
    //Slow performing business logic that returns a list
    return new ArrayList(); 
}

另一个作为

@Component
@CacheConfig(cacheNames = {"features"})
public class FeatureDaoImpl implements IFeatureDao {

@Override
@Cacheable
public List<Features> geFeaturesForProjectAndRelease(UserDto userDto, Set<Integer> reportProjectId, 
int releaseId) {
    //Slow performing business logic that returns a list
    return new ArrayList();
 }
}

我的缓存配置类为:

@Configuration
public class CaffeineCacheConfig {

 @Bean
 public CacheManager cacheManager() {
    CaffeineCacheManager cacheManager = new CaffeineCacheManager("features", "userStories");
    cacheManager.setCaffeine(caffeineCacheBuilder());
    return cacheManager;
 }

 Caffeine< Object, Object > caffeineCacheBuilder() {
    return Caffeine.newBuilder()
            .initialCapacity(100)
            .maximumSize(500)
            .expireAfterAccess(5, TimeUnit.MINUTES)
            .refreshAfterWrite(2, TimeUnit.MINUTES)
            .weakKeys()
            .recordStats();
 }
}

我正在使用spring boot :: 2.2.6.RELEASE,我的pom包括:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
    <groupId>com.github.ben-manes.caffeine</groupId>
    <artifactId>caffeine</artifactId>
    <version>2.8.2</version>
</dependency>

我错过了什么吗?我想维护一个缓存“功能”和“用户故事”,并在调用 DAO 方法后异步更新它。

我收到以下错误:

无法加载配置类:com.packageName.CaffeineCacheConfig

引起:java.lang.NoClassDefFoundError: com/github/benmanes/caffeine/cache/Caffeine

引起:java.lang.ClassNotFoundException:com.github.benmanes.caffeine.cache.Caffeine

我发现这些报告与类似问题有关:CaffeineGit-1CaffeineGit-Related

4

0 回答 0