Skip to content

Commit

Permalink
Bug fix: DiscoveryClient proxy casting null
Browse files Browse the repository at this point in the history
  • Loading branch information
aafwu00 committed Jul 4, 2018
1 parent b32a0f4 commit a7f1d57
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import javax.inject.Provider;

import org.springframework.aop.TargetSource;
import org.springframework.aop.framework.Advised;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
Expand All @@ -41,7 +43,6 @@
import com.netflix.evcache.connection.IConnectionFactoryProvider;
import com.netflix.evcache.pool.EVCacheClientPoolManager;

import static org.springframework.aop.framework.AopProxyUtils.getSingletonTarget;
import static org.springframework.aop.support.AopUtils.isAopProxy;

/**
Expand Down Expand Up @@ -90,7 +91,14 @@ private void appendProperty(final ConfigurableEnvironment environment) {

private DiscoveryClient discoveryClient(final EurekaClient eurekaClient) {
if (isAopProxy(eurekaClient)) {
return DiscoveryClient.class.cast(getSingletonTarget(eurekaClient));
final TargetSource targetSource = Advised.class.cast(eurekaClient).getTargetSource();
try {
return DiscoveryClient.class.cast(targetSource.getTarget());
// CHECKSTYLE:OFF
} catch (final Exception e) {
// CHECKSTYLE:ON
throw new IllegalStateException(e);
}
}
return DiscoveryClient.class.cast(eurekaClient);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
public class TodoRepository {
private static final Logger LOGGER = LoggerFactory.getLogger(TodoRepository.class);

@Cacheable(cacheNames = "TODO.todos", key = "'findAll'")
@Cacheable(cacheNames = "TODO", key = "'findAll'")
public List<Todo> findAll() {
LOGGER.info("CALLED");
return Arrays.asList(new Todo("first"), new Todo("second"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ logging:

evcache:
clusters:
- app-name: evcache
- name: TODO
app-name: EVCACHE
cache-prefix: todos
time-to-live: 5
server-group-retry: true
enable-exception-throwing: false

EVCACHE.use.inmemory.cache: true
EVCACHE.use.inmemory.cache: false
EVCACHE.inmemory.cache.duration.ms: 1000
EVCACHE.log.operation.calls: SET,DELETE,GMISS,TMISS,BMISS_ALL,TOUCH,REPLACE

0 comments on commit a7f1d57

Please sign in to comment.