我有一个正在开发网络服务,我需要验证在针对数据库的请求中发送的特定 httpheader。
我想使用 RestEasy 提供程序来做同样的事情,因为需要将相同的功能应用于所有服务。
@Provider
@ServerInterceptor
public class TestValidationInterceptor implements PreProcessInterceptor {
@Autowired
DetailsDelegate detailsDelegate;
@Override
public ServerResponse preProcess(HttpRequest request, ResourceMethod method) throws Failure, WebApplicationException {
//code to get data using detailsDelegate.
return null;
}
}
public interface DetailsDelegate {
String BEAN_ID = "DetailsDelegate";
/**
* @param appName
* @return
* @throws BaseException
*/
ServiceInfo getServiceDetails(String appName) throws BaseException;
}
@Service("detailsDelegate")
public class DetailsDelegateImpl implements DetailsDelegate {
@Override
public ServiceInfo getServiceDetails(String appName) throws BaseException {
return null;
}
}
详细信息委托实例未自动连线,并且为空。
有人可以解释为什么我面临这个问题。
最好让春天选择它的豆名,所以改变
@Service("detailsDelegate")
自
@Service
自动连线接口:
@Auowired
DetailsDelegate
最后,确保在您的配置中扫描定义了 DetailsDelegate 的包:
@ComponentScan("com.mypackage")
有关示例,请参阅 http://docs.spring.io/spring-javaconfig/docs/1.0.0.M4/reference/html/ch06s02.html