- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我收到以下错误。我还提到了与错误相关的 java 代码。
错误
以下是我得到的错误
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.util.List com.hp.ccue.serviceExchange.rest.OrderUtilsResource.orderUtils; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sawOrderUtils' defined in URL [jar:file:/opt/hp/propel/sx/WEB-INF/lib/sx-adapter-saw-2.20-SNAPSHOT.jar!/com/hp/ccue/serviceExchange/adapter/saw/util/SawOrderUtils.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [com.hp.ccue.serviceExchange.adapter.saw.SawOperationExecutor]: : No qualifying bean of type [com.hp.ccue.serviceExchange.adapter.saw.SawOperationExecutor] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.hp.ccue.serviceExchange.adapter.saw.SawOperationExecutor] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
... 58 more
SawOrderUtils.java错误相关的文件
package com.hp.ccue.serviceExchange.adapter.saw.util;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.hp.ccue.serviceExchange.SXConstants;
import com.hp.ccue.serviceExchange.adapter.saw.SawConstants;
import com.hp.ccue.serviceExchange.adapter.saw.SawOperationExecutor;
import com.hp.ccue.serviceExchange.aggregation.AggregationConstants;
import com.hp.ccue.serviceExchange.config.Configuration;
import com.hp.ccue.serviceExchange.message.MessageTransformer;
import com.hp.ccue.serviceExchange.message.builder.MessageConstants;
import com.hp.ccue.serviceExchange.utils.JsonUtils;
import com.hp.ccue.serviceExchange.utils.MessageUtils;
import com.hp.ccue.serviceExchange.utils.OrderUtilsBase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import static com.google.common.base.Objects.firstNonNull;
import static com.hp.ccue.serviceExchange.SXConstants.SawInstancesCfg;
import static com.hp.ccue.serviceExchange.utils.JsonUtils.getField;
@Component
public class SawOrderUtils extends OrderUtilsBase {
@Autowired
private Configuration configuration;
@Autowired
private MessageTransformer messageTransformer;
@Autowired
public SawOrderUtils(SawOperationExecutor operationExecutor) {
super(SawConstants.SAW_TYPE, operationExecutor, SawInstancesCfg.CFG_NAME);
}
@Override
public Map<String, String> getInstances() {
Map<String, Object> allInstanceConfigs = configuration.getConfiguration(getInstancesConfigPath());
Map<String, Object> instanceConfigs = Maps.filterValues(allInstanceConfigs, new Predicate<Object>() {
@Override
public boolean apply(Object input) {
@SuppressWarnings("unchecked")
Map<String, Object> instanceConfig = (Map<String, Object>) input;
return firstNonNull(JsonUtils.getBooleanField(instanceConfig, SawInstancesCfg.R2F_ENABLED), false);
}
});
return MessageUtils.instanceNames(instanceConfigs);
}
@Override
protected Map<String, String> fetchCatalogItems(String targetInstance) {
Map<String, Object> operationOutput = executeOperationForInstance(OPERATION_GET_CATALOG_ITEMS, targetInstance);
return getField(operationOutput, MessageConstants.RESULT);
}
@Override
protected List<String> fetchContacts(String targetInstance) {
Map<String, Object> operationOutput = executeOperationForInstance(OPERATION_GET_CONTACTS, targetInstance);
return getField(operationOutput, MessageConstants.RESULT);
}
@Override
public String getCatalogItemForm(String targetInstance, String itemId, String authToken) throws Exception {
Map<String, Object> offeringOperationOutput = executeOperationForInstance(AggregationConstants.OPERATION_GET_OFFERING, targetInstance,
ImmutableMap.<String, Object>of("itemID", itemId));
Map<String, Object> offering = getField(offeringOperationOutput, MessageConstants.RESULT);
if (offering == null) {
return "";
}
Map<String, Object> infrastructure = configuration.getConfiguration(SXConstants.INFRASTRUCTURE_CONFIG);
if (Objects.equals(JsonUtils.getStrField(offering, "summary", "type"), "SUPPORT")) {
List<Map<String, Object>> fields = JsonUtils.getField(offering, "form", "fields");
fields.removeIf(field -> {
final String id = JsonUtils.getStrField(field, "id");
return Objects.equals(id, "name") || Objects.equals(id, "description");
});
}
return messageTransformer.transformMessage(ImmutableMap.of(
"offering", offering,
"userAuthToken", authToken,
"infrastructure", infrastructure
), "ui/optionsHtmlTransform.ftl");
}
}
SawOperationExecutor.java
package com.hp.ccue.serviceExchange.adapter.saw;
import com.google.common.net.HttpHeaders;
import com.hp.ccue.serviceExchange.SXConstants.SawInstancesCfg;
import com.hp.ccue.serviceExchange.adapter.caseex.CxAwareOperationExecutor;
import com.hp.ccue.serviceExchange.adapter.saw.sawBeans.BulkOperationResult;
import com.hp.ccue.serviceExchange.adapter.saw.sawBeans.BulkOperationResult.CompletionStatuses;
import com.hp.ccue.serviceExchange.adapter.saw.sawBeans.BulkOperationResult.EntityResult;
import com.hp.ccue.serviceExchange.adapter.saw.sawBeans.BulkOperationResult.ErrorDetails;
import com.hp.ccue.serviceExchange.adapter.saw.util.SXSAWImplProperties;
import com.hp.ccue.serviceExchange.config.Configuration;
import com.hp.ccue.serviceExchange.http.HttpRequest;
import com.hp.ccue.serviceExchange.http.HttpResponse;
import com.hp.ccue.serviceExchange.http.HttpResponseWrapper;
import com.hp.ccue.serviceExchange.operation.OperationConstants;
import com.hp.ccue.serviceExchange.utils.JsonUtils;
import com.hp.ccue.serviceExchange.utils.ValidationUtils;
import org.apache.http.StatusLine;
import org.apache.http.message.BasicStatusLine;
import org.springframework.beans.factory.annotation.Autowired;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response.Status;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import static com.google.common.base.Objects.firstNonNull;
import static com.hp.ccue.serviceExchange.SXConstants.SUPPORTED_LANGUAGE_TAGS;
public class SawOperationExecutor extends CxAwareOperationExecutor {
private static final String LOGIN_REQUEST_URL = "/auth/authentication-endpoint/authenticate/login";
private static final String DOWNLOAD_ATTACHMENT_URL = "/frs/file-list/";
private static final String DOWNLOAD_IMAGES_URL = "/frs/image-list/";
private static final String IMAGES_URL = "/js/modules/saw/resources/images/";
@Autowired
private SawNotificationSetupExecutor notificationSetupExecutor;
private Set<String> operationsWithoutLogging;
@Autowired
private Configuration configuration;
public void setOperationsWithoutLogging(Set<String> operationsWithoutLogging) {
this.operationsWithoutLogging = operationsWithoutLogging;
}
public SawOperationExecutor() {
super(SawConstants.SAW_TYPE, SawInstancesCfg.CFG_NAME, true);
setDefaultHttpRequestContentType(MediaType.APPLICATION_JSON);
}
private Collection<String> getInstanceEndpoints(){
Collection<String> instanceEndpoints = new ArrayList<>();
Map<String, Object> allInstanceConfigs = configuration.getConfiguration(SawInstancesCfg.CFG_NAME);
for (Object value : allInstanceConfigs.values()) {
@SuppressWarnings("unchecked")
Map<String,Object> instance = (Map<String, Object>) value;
instanceEndpoints.add((String)instance.get("endpoint"));
}
return instanceEndpoints;
}
@Override
public void afterPropertiesSet() throws Exception {
super.afterPropertiesSet();
Set<String> skippedOperations = firstNonNull(operationsWithoutLogging, Collections.<String>emptySet());
for (String operation : skippedOperations) {
skipLoggingForOperation(operation);
}
}
@Override
protected void beforeExecuteOperation(String operationName, Map<String, Object> message, Map<String, Object> context, boolean doLogging) {
context.put(KEY_BUNDLE, SXSAWImplProperties.getMessagesBundle());
context.put(KEY_BUNDLES, SUPPORTED_LANGUAGE_TAGS.stream()
.collect(Collectors.toMap(Function.identity(), tag -> SXSAWImplProperties.getMessagesBundle(Locale.forLanguageTag(tag)))));
}
@Override
protected HttpResponse afterHttpResponseReceived(final HttpResponse httpResponse, final HttpRequest request) {
// SAW HTTP responses are buggy!
// we need to wrap them to determine proper Content-Type - the server does not send them
// we must wrap all methods which have something to do with Content-Type handling
HashMap<String, Object> context = new HashMap<>(); // unfortunately we don't have the context here; fixing this would required changing method signature
SawHttpResponseWrapper result = new SawHttpResponseWrapper(httpResponse, request);
getEffectiveStatusCode(httpResponse, context).ifPresent(result::setStatus);
return result;
}
private Optional<Integer> getEffectiveStatusCode(HttpResponse httpResponse, Map<String, Object> context) {
try {
Optional<BulkOperationResult> bulkOperationResult = parseBulkOperationResult(httpResponse, context);
if (bulkOperationResult.isPresent() && !Objects.equals(bulkOperationResult.get().getMeta().getCompletionStatus(), CompletionStatuses.FAILED)) {
return Optional.empty();
}
return bulkOperationResult.flatMap(SawOperationExecutor::getErrorDetails).map(ErrorDetails::getHttpStatus);
} catch (Exception e) {
return Optional.empty();
}
}
private class SawHttpResponseWrapper extends HttpResponseWrapper {
private final HttpRequest request;
private int statusCode;
private StatusLine statusLine;
public SawHttpResponseWrapper(HttpResponse httpResponse, HttpRequest request) {
super(httpResponse);
this.request = request;
this.statusCode = httpResponse.getStatusCode();
this.statusLine = httpResponse.getStatusLine();
}
@Override
public String getHeader(String headerName) {
if (headerName.equals(HttpHeaders.CONTENT_TYPE) && !isUrlKnownToHaveCorrectContentType(request.getUrl())) {
if (request.getUrl().contains(LOGIN_REQUEST_URL)) {
// authentication response is plaintext
return MediaType.TEXT_PLAIN;
} else {
// other responses are JSON
return MediaType.APPLICATION_JSON;
}
}
// else:
return super.getHeader(headerName);
}
@Override
public boolean hasStringContent() {
//noinspection SimplifiableIfStatement
if (!isUrlKnownToHaveCorrectContentType(request.getUrl())) {
return true;
}
return super.hasStringContent();
}
@Override
public boolean isJson() {
return getHeader(HttpHeaders.CONTENT_TYPE).equals(MediaType.APPLICATION_JSON);
}
private boolean isUrlKnownToHaveCorrectContentType(String url) {
for (String endpoint : getInstanceEndpoints()) {
if (url.startsWith(endpoint)) {
return url.contains(DOWNLOAD_ATTACHMENT_URL) || url.contains(IMAGES_URL) || url.contains(DOWNLOAD_IMAGES_URL);
}
}
return true;
}
@Override
public int getStatusCode() {
return statusCode;
}
@Override
public StatusLine getStatusLine() {
return statusLine;
}
void setStatus(int statusCode) {
this.statusCode = statusCode;
Status status = Status.fromStatusCode(statusCode);
String reasonPhrase = status != null ? status.getReasonPhrase() : String.format("HTTP %s", statusCode);
this.statusLine = new BasicStatusLine(getDelegate().getStatusLine().getProtocolVersion(), statusCode, reasonPhrase);
}
}
@Override
protected void executeNotificationSetup(
String entityId, Map<String,Object> entity, String checkOperation, Map<String, Object> checkOperationInputMessage, String catalogCallbackTemplate,
EntityRegistrationMode mode, Map<String, Object> context, Map<String, Object> stepConfig) throws Exception {
notificationSetupExecutor.executeNotificationSetup(
entityId, entity, checkOperation, checkOperationInputMessage, catalogCallbackTemplate, mode, context, stepConfig);
}
@Override
protected boolean isResponseSuccess(String operationName, Map<String, Object> stepConfig, HttpResponse httpResponse, Map<String, Object> message, Map<String, Object> context) {
final int statusCode = httpResponse.getStatusCode();
List<Integer> whiteListedStatuses = firstNonNull(JsonUtils.<List<Integer>>getField(stepConfig, OperationConstants.REPORT_SUCCESS_FOR_HTTP_STATUSES),
Collections.<Integer>emptyList());
//noinspection SimplifiableIfStatement
if (whiteListedStatuses.contains(statusCode)) {
return true;
}
return statusCode < 400;
}
private Optional<BulkOperationResult> parseBulkOperationResult(HttpResponse httpResponse, Map<String, Object> context) {
if (!httpResponse.isJson()) {
return Optional.empty();
}
Object jsonPayload;
try {
jsonPayload = parseJsonPayload(httpResponse, context);
} catch (IOException e) {
throw new RuntimeException(e);
}
if (!(jsonPayload instanceof Map)) {
return Optional.empty();
}
BulkOperationResult bulkOperationResult;
try {
//noinspection unchecked
bulkOperationResult = JsonUtils.readBean((Map<String, Object>) jsonPayload, BulkOperationResult.class);
ValidationUtils.validateBean(bulkOperationResult);
} catch (Exception e) {
return Optional.empty();
}
return Optional.of(bulkOperationResult);
}
@Override
protected String getDetailErrorMessage(String operationName, Map<String, Object> stepConfig, HttpResponse httpResponse, Map<String, Object> message, Map<String, Object> context) {
if (!httpResponse.isJson()) {
return null;
}
try {
ErrorDetails errorDetails = parseBulkOperationResult(httpResponse, context).flatMap(SawOperationExecutor::getErrorDetails).orElse(null);
if (errorDetails == null) {
return null;
}
final Integer httpStatus = errorDetails.getHttpStatus();
final String detailMessage = errorDetails.getMessage();
if (httpStatus == null || detailMessage == null) {
return null;
}
return String.format("%s (effective HTTP status: %s)", detailMessage, httpStatus);
} catch (RuntimeException e) {
log.debug("Failed to extract the detail message.", e);
return null;
}
}
private static Optional<ErrorDetails> getErrorDetails(BulkOperationResult bulkOperationResult) {
ErrorDetails errorDetails;
final List<EntityResult> entityResultList = bulkOperationResult.getEntityResultList();
if (entityResultList.size() != 1) { // let's cover only the case of single entity
errorDetails = bulkOperationResult.getMeta().getErrorDetails();
} else {
errorDetails = entityResultList.get(0).getErrorDetails();
}
return Optional.ofNullable(errorDetails);
}
}
SAWAdapterContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<context:component-scan base-package="com.hp.ccue.serviceExchange.adapter.saw"/>
<context:component-scan base-package="com.hp.ccue.serviceExchange.adapter.saw.util"/>
<context:component-scan base-package="com.hp.ccue.serviceExchange.adapter.saw.sawBeans"/>
<context:component-scan base-package="com.hp.ccue.serviceExchange.adapter.saw.caseex"/>
<context:component-scan base-package="com.hp.ccue.serviceExchange.adapter.saw.freemarker"/>
<context:component-scan base-package="com.hp.ccue.serviceExchange.adapter.saw.healthcheck"/>
<!-- <bean class="com.hp.ccue.serviceExchange.adapter.saw.SawOperationExecutor">
<property name="operationsWithoutLogging">
<set>
<value>getChangedIncidents</value>
<value>getChangedRequests</value>
<value>getChangedOfferings</value>
<value>getAggregationFeatures</value>
</set>
</property>
</bean> -->
<!--
To avoid IllegalArgumentException when autowiring lastUpdatedEntityDao in SawChangeListener:
http://stackoverflow.com/questions/18369258/spring-aop-at-service-layer
-->
<aop:aspectj-autoproxy proxy-target-class="true"/>
</beans>
最佳答案
我认为您在 SawOperationExecutor
类上缺少一个 @Component
注释
关于java - 通过索引为 0 的构造函数参数表示的不满足依赖关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37111879/
C语言sscanf()函数:从字符串中读取指定格式的数据 头文件: ?
最近,我有一个关于工作预评估的问题,即使查询了每个功能的工作原理,我也不知道如何解决。这是一个伪代码。 下面是一个名为foo()的函数,该函数将被传递一个值并返回一个值。如果将以下值传递给foo函数,
CStr 函数 返回表达式,该表达式已被转换为 String 子类型的 Variant。 CStr(expression) expression 参数是任意有效的表达式。 说明 通常,可以
CSng 函数 返回表达式,该表达式已被转换为 Single 子类型的 Variant。 CSng(expression) expression 参数是任意有效的表达式。 说明 通常,可
CreateObject 函数 创建并返回对 Automation 对象的引用。 CreateObject(servername.typename [, location]) 参数 serv
Cos 函数 返回某个角的余弦值。 Cos(number) number 参数可以是任何将某个角表示为弧度的有效数值表达式。 说明 Cos 函数取某个角并返回直角三角形两边的比值。此比值是
CLng 函数 返回表达式,此表达式已被转换为 Long 子类型的 Variant。 CLng(expression) expression 参数是任意有效的表达式。 说明 通常,您可以使
CInt 函数 返回表达式,此表达式已被转换为 Integer 子类型的 Variant。 CInt(expression) expression 参数是任意有效的表达式。 说明 通常,可
Chr 函数 返回与指定的 ANSI 字符代码相对应的字符。 Chr(charcode) charcode 参数是可以标识字符的数字。 说明 从 0 到 31 的数字表示标准的不可打印的
CDbl 函数 返回表达式,此表达式已被转换为 Double 子类型的 Variant。 CDbl(expression) expression 参数是任意有效的表达式。 说明 通常,您可
CDate 函数 返回表达式,此表达式已被转换为 Date 子类型的 Variant。 CDate(date) date 参数是任意有效的日期表达式。 说明 IsDate 函数用于判断 d
CCur 函数 返回表达式,此表达式已被转换为 Currency 子类型的 Variant。 CCur(expression) expression 参数是任意有效的表达式。 说明 通常,
CByte 函数 返回表达式,此表达式已被转换为 Byte 子类型的 Variant。 CByte(expression) expression 参数是任意有效的表达式。 说明 通常,可以
CBool 函数 返回表达式,此表达式已转换为 Boolean 子类型的 Variant。 CBool(expression) expression 是任意有效的表达式。 说明 如果 ex
Atn 函数 返回数值的反正切值。 Atn(number) number 参数可以是任意有效的数值表达式。 说明 Atn 函数计算直角三角形两个边的比值 (number) 并返回对应角的弧
Asc 函数 返回与字符串的第一个字母对应的 ANSI 字符代码。 Asc(string) string 参数是任意有效的字符串表达式。如果 string 参数未包含字符,则将发生运行时错误。
Array 函数 返回包含数组的 Variant。 Array(arglist) arglist 参数是赋给包含在 Variant 中的数组元素的值的列表(用逗号分隔)。如果没有指定此参数,则
Abs 函数 返回数字的绝对值。 Abs(number) number 参数可以是任意有效的数值表达式。如果 number 包含 Null,则返回 Null;如果是未初始化变量,则返回 0。
FormatPercent 函数 返回表达式,此表达式已被格式化为尾随有 % 符号的百分比(乘以 100 )。 FormatPercent(expression[,NumDigitsAfterD
FormatNumber 函数 返回表达式,此表达式已被格式化为数值。 FormatNumber( expression [,NumDigitsAfterDecimal [,Inc
我是一名优秀的程序员,十分优秀!