【发布时间】:2020-11-20 12:19:23
【问题描述】:
当我开始将项目部署到 Tomcat 上时,我收到错误消息
说明:绑定属性失败 'spring.jackson.deserialization' 到 java.util.Map
: 原因:没有找到能够从类型 [java.lang.String] 转换为类型 [java.util.Map ] 的转换器操作: 更新应用程序的配置
我的 application.properties 是空的
通过 gradle 构建项目。
build.gradle
plugins {
id 'org.springframework.boot' version '2.3.2.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
id 'war'
}
group = 'com.ladon'
version = '0.0.1'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'com.h2database:h2'
runtimeOnly 'com.microsoft.sqlserver:mssql-jdbc'
runtimeOnly 'mysql:mysql-connector-java'
runtimeOnly 'org.apache.derby:derby'
runtimeOnly 'org.postgresql:postgresql'
compileOnly 'org.projectlombok:lombok:1.18.12'
annotationProcessor 'org.projectlombok:lombok:1.18.12'
testCompileOnly 'org.projectlombok:lombok:1.18.12'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
package com.ladon.jsonserver;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(JsonserverApplication.class);
}
}
package com.ladon.jsonserver;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class JsonserverApplication {
public static void main(String[] args) {
SpringApplication.run(JsonserverApplication.class, args);
}
}
package com.ladon.jsonserver.structure;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.Data;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"ACTIONS",
"EcrSN",
"Group",
"ErrorCode",
"ErrorCodeMessage"
})
public @Data class DeviceStatusUpdateResponse {
@JsonProperty("ACTIONS")
private List<DeviceStatusUpdateACTIONSResponse> aCTIONS = null;
@JsonProperty("EcrSN")
private Integer ecrSN;
@JsonProperty("Group")
private String group;
@JsonProperty("ErrorCode")
private Integer errorCode;
@JsonProperty("ErrorCodeMessage")
private String errorCodeMessage;
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
public DeviceStatusUpdateResponse() {
}
}
package com.ladon.jsonserver.structure;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.Data;
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"TypeId",
"Id",
"CreationTimestamp",
"ExecutionTimestamp",
"Note",
"DownloadURL",
"DeployType",
"NewEcrFwVersion",
"NewEcrFwVersionDescription",
"MD",
"CMD"
})
public @Data class DeviceStatusUpdateACTIONSResponse implements Serializable {
@JsonProperty("TypeId")
private Integer typeId;
@JsonProperty("Id")
private Integer id;
@JsonProperty("CreationTimestamp")
private String creationTimestamp;
@JsonProperty("ExecutionTimestamp")
private String executionTimestamp;
@JsonProperty("Note")
private String note;
@JsonProperty("DownloadURL")
private String downloadURL;
@JsonProperty("DeployType")
private String deployType;
@JsonProperty("NewEcrFwVersion")
private Integer newEcrFwVersion;
@JsonProperty("NewEcrFwVersionDescription")
private String newEcrFwVersionDescription;
@JsonProperty("MD")
private String mD;
@JsonProperty("CMD")
private List<DeviceStatusUpdateACTIONSCMDResponse> cMD = null;
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
public DeviceStatusUpdateACTIONSResponse() {
}
/**
*
* @param note
* @param newEcrFwVersionDescription
* @param newEcrFwVersion
* @param mD
* @param creationTimestamp
* @param downloadURL
* @param typeId
* @param id
* @param cMD
* @param deployType
* @param executionTimestamp
*/
public DeviceStatusUpdateACTIONSResponse(Integer typeId, Integer id, String creationTimestamp, String executionTimestamp, String note, String downloadURL, String deployType, Integer newEcrFwVersion, String newEcrFwVersionDescription, String mD, List<DeviceStatusUpdateACTIONSCMDResponse> cMD) {
super();
this.typeId = typeId;
this.id = id;
this.creationTimestamp = creationTimestamp;
this.executionTimestamp = executionTimestamp;
this.note = note;
this.downloadURL = downloadURL;
this.deployType = deployType;
this.newEcrFwVersion = newEcrFwVersion;
this.newEcrFwVersionDescription = newEcrFwVersionDescription;
this.mD = mD;
this.cMD = cMD;
}
}
package com.ladon.jsonserver.structure;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.Data;
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"CmdId",
"Commandd",
"Psw",
"Body",
"ExtendedDeviceStatus",
"OnlyIfPreviousOk",
"StateExe"
})
public @Data class DeviceStatusUpdateACTIONSCMDResponse implements Serializable {
@JsonProperty("CmdId")
private Integer cmdId;
@JsonProperty("Commandd")
private String commandd;
@JsonProperty("Psw")
private Integer psw;
@JsonProperty("Body")
private String body;
@JsonProperty("ExtendedDeviceStatus")
private Integer extendedDeviceStatus;
@JsonProperty("OnlyIfPreviousOk")
private Boolean onlyIfPreviousOk;
@JsonProperty("StateExe")
private Integer stateExe;
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
public DeviceStatusUpdateACTIONSCMDResponse() {
}
public DeviceStatusUpdateACTIONSCMDResponse(Integer cmdId, String commandd, Integer psw, String body, Integer extendedDeviceStatus, Boolean onlyIfPreviousOk, Integer stateExe) {
super();
this.cmdId = cmdId;
this.commandd = commandd;
this.psw = psw;
this.body = body;
this.extendedDeviceStatus = extendedDeviceStatus;
this.onlyIfPreviousOk = onlyIfPreviousOk;
this.stateExe = stateExe;
}
}
package com.ladon.jsonserver.controller;
import com.ladon.jsonserver.structure.DeviceStatusUpdateResponse;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/RemoteControl")
public class DeviceStatusUpdateResponseController {
@ResponseBody
@ResponseStatus(value = HttpStatus.OK)
@RequestMapping(value = "/UpdateDeviceStatus/{sernum}",produces = MediaType.APPLICATION_JSON_VALUE)
public DeviceStatusUpdateResponse DeviceStatusUpdateResponse(@PathVariable("sernum") long sernum)
{
DeviceStatusUpdateResponse device = new DeviceStatusUpdateResponse();
return device;
}
}
我的错误在哪里?
【问题讨论】:
-
Update your application's configuration表示配置有问题。能否列出所有配置文件及其包含的内容? -
您好,“更新应用程序的配置”是什么意思?如果您的意思是 application.properties,则该文件为空。抱歉,这是我在 Spring 中的第一步,我不确定我是否正确理解了您的要求。
-
Update your application's configuration是我在您问题的异常消息中看到的内容。这可能是Spring提出的建议操作。如果此文件为空,请尝试设置至少一个属性并检查会发生什么。例如:spring.jackson.deserialization.fail-on-unknown-properties = true -
嗨,我刚刚将此参数添加到 application.properties。没有影响。我收到新的错误消息