我目前正在尝试InjectableProvider
用泽西岛创造一个,但我不能让泽西拿起它.
我找不到它的用法的任何真实例子,甚至除了@Provider
在实现上使用注释之外如何获取它.看似在泽西岛内写作的人在某些帖子中暗示这足以让它捡起来.
我是否需要指定一些SPI服务文件,或者将其添加到某个工厂?
注意:我在Glassfish 3.1中运行,并使用Spring 3.1.Spring可能以某种方式接管自动加载Provider
s 似乎是合理的.但是,我只是不知道.我不是在使用Spring来管理下面建议的InjectableProvider,也不是我试图以其他方式添加它,这可能是我的问题.
import com.sun.jersey.core.spi.component.ComponentContext;
import com.sun.jersey.spi.inject.Injectable;
import com.sun.jersey.spi.inject.PerRequestTypeInjectableProvider;
public abstract class AbstractAttributeInjectableProvider<T>
extends PerRequestTypeInjectableProvider<AttributeParam, T>
{
protected final Class<T> type;
public AbstractAttributeInjectableProvider(Class<T> type)
{
super(type);
this.type = type;
}
@Override
public Injectable<T> getInjectable(ComponentContext componentContext,
AttributeParam attributeParam)
{
return new AttributeInjectable<T>(type, attributeParam.value());
}
}
Run Code Online (Sandbox Code Playgroud)
基本实施:
import javax.ws.rs.ext.Provider;
@Component // <- Spring Annotation
@Provider // <- Jersey Annotation
public class MyTypeAttributeInjectableProvider
extends AbstractAttributeInjectableProvider<MyType>
{
public MyTypeAttributeInjectableProvider()
{
super(MyType.class);
}
}
Run Code Online (Sandbox Code Playgroud)
参考 …