我在我的应用程序中使用springboot + jersey。我正在使用嵌入式tomcat。以下是API的定义。
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
public Response createNewBadge(@FormDataParam("name") String name,
@DefaultValue("0") @FormDataParam("grade") int grade,
@DefaultValue("0") @FormDataParam("point") int point,
@FormDataParam("file") InputStream fileInputStream,
@FormDataParam("file") FormDataContentDisposition disposition) {
...
}
当我启动应用程序并访问此API提供的路径时,我将得到以下错误。我在这里错过了什么吗?
WARNING: No injection source found for a parameter of type public javax.ws.rs.core.Response com.ct.api.BadgeAPI.createNewBadge(java.lang.String,int,int,java.io.InputStream,org.glassfish.jersey.media.multipart.FormDataContentDisposition) at index 0.
2016-02-26 13:42:14.457 ERROR 35414 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : StandardWrapper.Throwable
org.glassfish.jersey.server.model.ModelValidationException: Validation of the application resource model has failed during application initialization.
[[FATAL] No injection source found for a parameter of type public javax.ws.rs.core.Response com.ct.api.BadgeAPI.createNewBadge(java.lang.String,int,int,java.io.InputStream,org.glassfish.jersey.media.multipart.FormDataContentDisposition) at index 0.; source='ResourceMethod{httpMethod=POST, consumedTypes=[multipart/form-data], producedTypes=[application/json], suspended=false, suspendTimeout=0, suspendTimeoutUnit=MILLISECONDS, invocable=Invocable{handler=ClassBasedMethodHandler{handlerClass=class com.ct.api.BadgeAPI, handlerConstructors=[org.glassfish.jersey.server.model.HandlerConstructor@22393b97]}, definitionMethod=public javax.ws.rs.core.Response com.ct.api.BadgeAPI.createNewBadge(java.lang.String,int,int,java.io.InputStream,org.glassfish.jersey.media.multipart.FormDataContentDisposition), parameters=[Parameter [type=class java.lang.String, source=name, defaultValue=null], Parameter [type=int, source=grade, defaultValue=0], Parameter [type=int, source=point, defaultValue=0], Parameter [type=class java.io.InputStream, source=file, defaultValue=null], Parameter [type=class org.glassfish.jersey.media.multipart.FormDataContentDisposition, source=file, defaultValue=null]], responseType=class javax.ws.rs.core.Response}, nameBindings=[]}']
at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:555) ~[jersey-server-2.22.1.jar:na]
at org.glassfish.jersey.server.ApplicationHandler.access$500(ApplicationHandler.java:184) ~[jersey-server-2.22.1.jar:na]
at org.glassfish.jersey.server.ApplicationHandler$3.call(ApplicationHandler.java:350) ~[jersey-server-2.22.1.jar:na]
at org.glassfish.jersey.server.ApplicationHandler$3.call(ApplicationHandler.java:347) ~[jersey-server-2.22.1.jar:na]
at org.glassfish.jersey.internal.Errors.process(Errors.java:315) ~[jersey-common-2.22.1.jar:na]
答案 0 :(得分:2)
使用Spring启动时,支持2.15版本的运动衫。请更改多部分球衣依赖的版本。
答案 1 :(得分:1)
经过一番搜索,我找出了根本原因。我需要在球衣配置上注册MultiPartFeature类,如下所示:
@Configuration
public class JerseyConfiguration extends ResourceConfig {
public JerseyConfiguration(){
register(MultiPartFeature.class);
}
}