当我将cache:annotation-driven添加到我的应用程序上下文时,我收到以下异常:
Superclass has no null constructors but no arguments were given
我有一个名为PersistController的类,它有用 @Cachable(..)注释的方法,我在应用程序上下文中声明一个实例,如下所示:
<!-- The culprit, for whatever reason -->
<cache:annotation-driven />
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches">
<set>
<bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" p:name="primaryTest"/>
<bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" p:name="secondaryTest"/>
</set>
</property>
</bean>
<!-- The problem began when I started requiring a String in the constructor. -->
<bean id="persistController" class="com.sei.poc.controller.PersistController" >
<constructor-arg> <value>${cache.nextVersionPostfix}</value></constructor-arg>
</bean>
当我删除cache:annotation-driven行时,错误消失了,而是收到一个错误,表明带注释的缓存组件不工作(显然)。这意味着上面声明的PersistController已正确声明,并且 Spring 完全能够调用正确的构造函数、解析属性并将字符串作为参数注入。
那么为什么我添加cache:annotation-driven时出现错误?
我相信这与 Spring 使用@Cacheable(..)或任何 Spring 缓存注释自动实例化类的实例有关。如果是这种情况,我想知道是否有一种方法可以将我的属性指定为其构造中的参数。
如果我不能为这些类声明构造函数,(如果你知道答案,我会假设你比我更了解 spring-context-flow)将@Autowired或@Value(..)注释允许生成的类检测财产?
谢谢大家的阅读。