2013-05-22 6 views
1

나는 문제를 발견/:봄 @EnableCaching이를 주입은 autowire가 문제 @

@Configuration 
@EnableCaching 
public class CacheConfig { 

    @Inject 
    private DataSource dataSource; 

    @Bean 
    public CacheManager cacheManager(){ 
     SimpleCacheManager cacheManager = new SimpleCacheManager(); 
     cacheManager.setCaches(Arrays.asList(new ConcurrentMapCache("books"))); 
     return cacheManager; 
    } 

    @Configuration 
    static class DevProfileConfig { 
     @Bean(destroyMethod = "shutdown") 
     public DataSource dataSource() { 
      EmbeddedDatabaseFactory factory = new EmbeddedDatabaseFactory(); 
      factory.setDatabaseType(EmbeddedDatabaseType.HSQL); 
      return factory.getDatabase(); 
     } 
    } 
} 

응용 프로그램 컨텍스트 발사기 :

public class CacheConfigLauncher { 
    public static void main(String args[]){ 
     ApplicationContext springAppContext = new AnnotationConfigApplicationContext(CacheConfig.class); 
    } 
} 

에로 R :

Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.cache.CacheManager spring.samples.config.CacheConfig.cacheManager()] threw exception; nested exception is java.lang.IllegalArgumentException: Object of class [null] must be an instance of interface org.springframework.beans.factory.config.ConfigurableBeanFactory at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:188) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:573) ... 76 more

Caused by: java.lang.IllegalArgumentException: Object of class [null] must be an instance of interface org.springframework.beans.factory.config.ConfigurableBeanFactory at org.springframework.util.Assert.isInstanceOf(Assert.java:339) at org.springframework.util.Assert.isInstanceOf(Assert.java:319) at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.getBeanFactory(ConfigurationClassEnhancer.java:414) at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:289) at spring.samples.config.CacheConfig$$EnhancerByCGLIB$$f6ceccea.cacheManager() at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:491) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:166) ... 77 more

을 그러나 당신이 Inject'ed 필드 또는 @EnableCaching 주석 구성 @ 중 하나를 주석 경우 오류없이 bootstraped됩니다!

나를 위해 버그가 있습니다. 다른 사람이 똑같은 문제에 직면했는지, 아니면 내가 어리 석음을 잃어 버렸을까요?

올렉

답변

0

문제가 봄 v4.0.0.M2에서 수정되었습니다 감사합니다!