相关疑难解决方法(0)

Guice:无法在Request范围中注入带注释的类型

我试图将一个带注释的变量注入REQUEST范围:

Map<Key<?>, Object> seedMap = ImmutableMap.<Key<?>, Object>builder().
  put(Key.get(String.class, Names.named("name")), name).build();
return ServletScopes.scopeRequest(new InjectingCallable<>(injector, 
  GetModule.class), seedMap).call();
Run Code Online (Sandbox Code Playgroud)

其中,InjectingCallable在REQUEST范围内注入GetModule:

/**
 * A Callable that is constructed in one scope and injects a Callable into a potentially separate
 * scope.
 * <p/>
 * @param <V> the type of object returned by the Callable
 * @author Gili Tzabari
 */
public final class InjectingCallable<V> implements Callable<V>
{
    private final Injector injector;
    private final Class<? extends Callable<V>> delegate;

    /**
     * Creates a new InjectingCallable.
     * <p/>
     * …
Run Code Online (Sandbox Code Playgroud)

java guice

2
推荐指数
1
解决办法
6556
查看次数

标签 统计

guice ×1

java ×1