我已经用Spring Boot 1.5.17创建了一个REST API。
每当我在请求映射中使用单词services
时,都会出现“ Invalid Content-Type"
错误”
"exception": "org.springframework.ws.soap.SoapMessageCreationException",
"message": "Could not create message from InputStream: Invalid Content-Type:application/json. Is this an error message instead of a SOAP response?; nested exception is com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Invalid Content-Type:application/json. Is this an error message instead of a SOAP response?",
请求映射的原因是@RequestMapping("services/v1.0/operation")
如果我使用/services
之外的其他任何东西,例如/service
,/abcd
,/api
,则一切正常。我真的很困惑,无法理解是什么原因造成的?
===================添加更多详细信息===============
配置类
package com.xxx.xxx.api.rest.security;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
@Configuration
public class SpringSecurityConfig {
@Value("${WS.SERVICE.USERNAME.xxxxx}")
private String XXXXXUsername;
@Value("${WS.SERVICE.PASSWORD.xxxxx}")
private String XXXXPassword;
@Bean
public UserDetailsService userDetailsService() {
InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
manager.createUser(User
.withUsername(XXXXXUsername)
.password(XXXXXPassword)
.roles("USER").build());
return manager;
}
}
Controller:已经在使用@RestController
@RestController
@ApiResponses({ @ApiResponse(code = 500, message = "Internal Server Error" ,response = ErrorMessage.class),
@ApiResponse(code = 400, message = "Bad Request" ,response = ErrorMessage.class)
})
@RequestMapping("services/v1.0/account")
public class AccountsController {
static final Logger log = LoggerFactory.getLogger(AccountsController.class);
@Autowired
AccountsFacade accountsFacade;
@RequestMapping(path="/getXxxXxxNameAndXxxxxName",produces="application/json", consumes="application/json" , method=RequestMethod.POST)
public ResponseEntity<AccountDetailsResponse> getXxxXxxNameAndXxxxxName(@Valid @RequestBody AccountDetailsRequest accountDetailsRequest ) {
log.debug("START getXxxXxxNameAndXxxxxName : AccountDetailsRequest ({})",accountDetailsRequest);
AccountDetailsResponse accountDetailsResponse = accountsFacade.getXxxXxxNameAndXxxxxName(accountDetailsRequest);
log.debug("END getXxxXxxNameAndXxxxxName : accountDetailsResponse ({})", accountDetailsResponse);
return new ResponseEntity<AccountDetailsResponse>(accountDetailsResponse,HttpStatus.OK);
}
我正在使用Gradle ..以下是内容
buildscript {
ext {
springBootVersion = '1.5.17.RELEASE'
}
repositories {
maven {
credentials {
username "${artifactoryUser}"
password "${artifactoryPassword}"
}
url "${resolveUrl}"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'maven'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
apply from: '../properties.gradle'
ext.branch="${getEnvProperties('BRANCH')}"
ext.branch_version=branch.substring(0,3)
ext.version_major=branch_version
ext.build_number=System.getenv("BUILD_NUMBER") as Integer ?: 0
ext.version_patch="${getEnvProperties('VERSION_PATCH')}"
ext.semantic_version="${getEnvProperties('SEMANTIC_VERSION')}"
ext.pub_version = "${version_major}.${version_patch}-${semantic_version}"
version=''
war {
manifest {
archiveName = "${WAR_FILE_XXXXX_REST_APP}.war"
attributes 'Implementation-Title': "${WAR_FILE_XXXXX_REST_APP}",
'Implementation-Version':"${pub_version}.${build_number}",
"Implementation-Timestamp": new Date(),
"Built-By" : 'Jenkins',
"Java-Version" :System.getProperty("java.version"),
"Java-implementor" :System.getProperty("java.vm.vendor")
}
}
configurations {
compile
runtime {
extendsFrom compile,testCompile
exclude(group: 'org.glassfish.hk2.external', module:'asm-all-repackaged')
exclude(group: 'com.sun.xml.bind', module:'jaxb-impl')
exclude(group: 'sun-jaxb', module:'jaxb-impl')
exclude(group: 'org.springframework.ws', module:'spring-oxm-tiger')
exclude(group: 'ch.qos.logback', module:'logback-classic')
exclude(group: 'ch.qos.logback', module:'logback-core')
exclude(group: 'org.slf4j', module:'slf4j-nop')
all*.exclude group: "javax.servlet", module: "servlet-api"
all*.exclude group: "com.h2database", module: "h2"
all*.exclude group: "org.springframework.boot", module: "spring-boot-starter-logging"
all*.exclude group: "commons-logging", module: "commons-logging"
all*.exclude group: "commons-logging", module: "commons-logging-api"
}
emma
}
dependencies {
compile project(':OtherDependency')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-aop')
compile('org.springframework.boot:spring-boot-starter-jersey')
compile('org.springframework.boot:spring-boot-starter-tomcat')
compile('org.springframework.boot:spring-boot-gradle-plugin')
compile('org.springframework.boot:spring-boot-starter-security')
compile ([group: 'xxx', name: 'InternalJar', version: '1.0'])
compile ([group: 'org.springframework.boot', name: 'spring-boot-starter-log4j', version: '1.3.8.RELEASE'])
testCompile('org.springframework.boot:spring-boot-starter-test')
compile ([group: 'org.springframework.integration', name: 'spring-integration-ws', version: '4.3.17.RELEASE'])
compile ([group: 'org.springframework.integration', name: 'spring-integration-stream', version: '4.3.17.RELEASE'])
compile ([group: 'org.springframework.integration', name: 'spring-integration-xml', version: '4.3.17.RELEASE'])
compile ([group: 'org.springframework.integration', name: 'spring-integration-file', version: '4.3.17.RELEASE'])
compile ([group: 'org.springframework.integration', name: 'spring-integration-http', version: '4.3.17.RELEASE'])
compile ([group: 'org.springframework.integration', name: 'spring-integration-ip', version: '4.3.17.RELEASE'])
compile ([group: 'org.springframework.integration', name: 'spring-integration-stream', version: '4.3.17.RELEASE'])
compile ([group: 'org.springframework', name: 'spring-orm', version: '3.2.8.RELEASE'])
compile ([group: 'org.springframework', name: 'spring-oxm', version: '3.2.8.RELEASE'])
compile ([group: 'org.apache.velocity', name: 'velocity', version: '1.7'])
compile ([group: 'commons-httpclient', name: 'commons-httpclient', version: '3.1'])
compile ([group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.3'])
compile ([group: 'org.springframework', name: 'spring-beans', version: '4.3.20.RELEASE'])
compile ([group: 'org.springmodules', name:'spring-modules-jakarta-commons',version: '0.8a'])
compile("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
compile('io.springfox:springfox-swagger2:2.8.0')
compile('io.springfox:springfox-swagger-ui:2.8.0')
testCompile('org.springframework.boot:spring-boot-starter-test')
compile ([group: 'org.springframework.ws', name: 'spring-ws-security', version: '2.2.2.RELEASE'])
{
exclude(group: 'org.springframework')
exclude(group: 'org.springframework.security')
exclude(group:'org.slf4j',module:'log4j-over-slf4j')
exclude(group: 'javax.xml.crypto')
transitive = false
}
compile ([group: 'org.apache.ws.security', name: 'wss4j', version: '1.6.5'])
{
exclude(group: 'org.springframework.security')
transitive = false
}
compile ([group: 'com.sun.xml.wsit', name: 'xws-security', version: '1.3.1'])
compile ([group: 'org.apache.santuario', name: 'xmlsec', version: '1.5.4'])
/** Test **/
testCompile ([group: 'org.springframework', name: 'spring-test', version: '4.3.20.RELEASE'])
{
transitive = false
}
testCompile([group:'org.powermock',name:'powermock-api-mockito',version:'1.6.2'])
testCompile([group:'org.powermock',name:'powermock-api-support',version:'1.6.2'])
testCompile([group:'org.powermock',name:'powermock-core',version:'1.6.2'])
testCompile([group:'org.powermock',name:'powermock-reflect',version:'1.6.2'])
testCompile([group:'org.powermock',name:'powermock-module-junit4',version:'1.6.2'])
testCompile([group:'org.powermock',name:'powermock-module-junit4-common',version:'1.6.2'])
testCompile([group:'org.apache.httpcomponents', name: 'httpclient', version: '4.5.3'])
testCompile([group:'commons-httpclient', name: 'commons-httpclient', version: '3.1'])
testCompile([group:'io.rest-assured',name:'rest-assured',version:'3.0.0'])
testCompile([group:'org.glassfish.jersey.containers',name:'jersey-container-grizzly2-http',version:'2.19'])
testCompile([group:'org.glassfish.grizzly',name:'grizzly-http-server',version:'2.3.19'])
testCompile([group:'junit',name:'junit',version:'4.12'])
testCompile([group:'mysql',name:'mysql-connector-java',version:'5.1.45'])
testRuntime ([group: 'org.mortbay.jetty', name: 'servlet-api', version: '3.0.20100224'])
}/*****************************************ADDED To RESOLVE THE PROPERTIES.GRADLE*********/
def String getEnvProperties(String propertyName)
{
String resolvedPropertyName = System.getenv(propertyName);
if (resolvedPropertyName== null && hasProperty(propertyName))
{
resolvedPropertyName = this.properties[propertyName]
}
return resolvedPropertyName
}