在 Spring 应用程序(不是 spring-boot)中,我在同一个 bean 方法上使用 javanica @HystrixCommand 注释和 spring cache @Cacheable 注释,Spring 在 Hystrix 建议之前执行缓存建议。这就是我在等待的,但对我来说,没有任何配置的缓存建议和 hystrix 建议在 spring 中具有相同的顺序:LOWEST_PRECEDENCE。
我不知道是什么产生了这个订单:它是在某处定义的还是未定义的订单,我很幸运能有好的订单?必须做些什么来确保缓存建议在 Hystrix 建议之前执行(在缓存上设置顺序:在 LOWEST_PRECEDENCE 之前设置注释驱动?)
这是我的代码示例:
...
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
...
@Service
@Slf4j
@CacheConfig(cacheManager="myCacheManager")
public class MyRessourcesImpl implements MyRessources {
...
@Override
@HystrixCommand(commandProperties = {
@HystrixProperty(name = "execution.isolation.strategy", value = "SEMAPHORE"),
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "10000") })
@Cacheable("cacheName") //from spring cache
public Map<String, String> getTheMap() {
...
}
...
}
Run Code Online (Sandbox Code Playgroud)
使用此弹簧配置:
<bean id="myCache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" …Run Code Online (Sandbox Code Playgroud)