2017-05-15 3 views
0

구성 : 스프링 컨텍스트의봄 캐싱이 작동하지 않습니다 (SimpleCacheManager)

@Configuration 
@EnableCaching 
@ComponentScan("by.bsu.chemistry") 
public class AppConfig { 

    @Bean 
    public CacheManager cacheManager() { 
     SimpleCacheManager manager = new SimpleCacheManager(); 
     manager.setCaches(Collections.singleton(new ConcurrentMapCache("panes"))); 
     return manager; 
    } 
} 

초기화 :

public class Main extends Application { 

    public static BorderPane borderPane; 

    ConfigurableApplicationContext context; 

    @Override 
    public void init() throws Exception { 
     super.init(); 
     context = new AnnotationConfigApplicationContext(AppConfig.class); 
    } 

그리고 캐시의 사용이 BoxUtils 클래스에 있습니다

@Component 
public class BoxUtils { 

//some code 

@Cacheable(value = {"panes"}) 
    public Pane getDefaultPane(String title){ 

     VBox vBox = new VBox(); 

     //some code 

     System.out.println("getDefaultPane(" + title + ") = " + vBox); 

     return vBox; 
    } 

때마다 방법 getDefaultPane(String title)이 호출되면 콘솔의 프로그램 출력 "getDefaultPane(......) = [email protected] "따라서 캐싱 결과 대신 매번 메서드가 작동했습니다. 내가 뭘 잘못하고 있니?

* 실행 전에 스택 트레이스에서 getDefaultPane 캐시 프록시가 호출되지 않습니다!

** (org.springframework.cache를) 로그의 추적 레벨을 설정 한 후

DEBUG AnnotationCacheOperationSource [AbstractFallbackCacheOperationSource.java:101] Adding cacheable method 'getDefaultPane' with attribute: [Builder[public javafx.scene.layout.Pane by.bsu.chemistry.util.BoxUtils.getDefaultPane(java.lang.String)] caches=[panes] | key='' | keyGenerator='' | cacheManager='' | cacheResolver='' | condition='' | unless='' | sync='false'] 

답변

0
  1. 확인 @CacheablegetDefaultPaneorg.springframework.cache.annotation.Cacheable
  2. 설정 중단 점이며, 캐시 프록시
  3. 를 호출하면 스택 트레이스에서 볼
  4. 로깅 설정 org.springframework.cache을 추적 수준
관련 문제