[英]Jersey ModelValidationException - No Injection source found
I got a weird problem, that I absolutely doesn't understand, with Jersey 2.6.我遇到了一个奇怪的问题,我绝对不明白,使用Jersey 2.6。
I can't explain why, but one of the query parameter make jersey throw a ModelValidationException我无法解释为什么,但查询参数之一使球衣抛出ModelValidationException
@ApiOperation("Save")
@PUT
public Response save(
@HeaderParam("token") final String token,
@QueryParam("someValue") final SomeValueDTO someValue,
@QueryParam("anotherParam") final int anotherParam) throws TechnicalException {
return Response.ok().build();
}
the queryParam 'someValue' make jersey throw: queryParam 'someValue' 使球衣抛出:
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 ch.rodano.studies.api.resources.PagesResource.save(java.lang.String,ch.rodano.studies.api.dto.JSONValueDTO,int) throws ch.rodano.studies.exceptions.RightException,ch.rodano.studies.configuration.exceptions.NoNodeException at index 1.; source='ResourceMethod{httpMethod=PUT, consumedTypes=[], producedTypes=[application/json], suspended=false, suspendTimeout=0, suspendTimeoutUnit=MILLISECONDS, invocable=Invocable{handler=ClassBasedMethodHandler{handlerClass=class ch.rodano.studies.api.resources.PagesResource, handlerConstructors=[org.glassfish.jersey.server.model.HandlerConstructor@41ed3918]}, definitionMethod=public javax.ws.rs.core.Response ch.rodano.studies.api.resources.PagesResource.save(java.lang.String,ch.rodano.studies.api.dto.JSONValueDTO,int) throws ch.rodano.studies.exceptions.RightException,ch.rodano.studies.configuration.exceptions.NoNodeException, parameters=[Parameter [type=class java.lang.String, source=token, defaultValue=null], Parameter [type=class ch.rodano.studies.api.dto.JSONValueDTO, source=valuesASD, defaultValue=null], Parameter [type=int, source=visitPk, defaultValue=null]], responseType=class javax.ws.rs.core.Response}, nameBindings=[]}']
If I use String instead of SomeValueDTO everything's okay.如果我使用 String 而不是 SomeValueDTO 一切都好。 SomeValueDTO is a quite classic POJO with an empty constructor and getters/setters.
SomeValueDTO 是一个非常经典的 POJO,带有一个空的构造函数和 getter/setter。
If someone has an idiea !!如果有人有想法!!
SomeValueDTO
needs to be convertible. SomeValueDTO
需要可转换。 Options to accomplish this:完成此操作的选项:
public static SomeValueDTO valueOf(String param)
that returns the type (SomeValueDTO)public static SomeValueDTO valueOf(String param)
)public static SomeValueDTO fromString(String param)
that returns the type (SomeValueDTO)public static SomeValueDTO fromString(String param)
)ParamConverter
.ParamConverter
。 You can see an example hereIn either of the first three cases, you'll want to construct the instance accordingly by parsing the String either in the constructor or in one of the above-mentioned methods.在前三种情况中的任何一种情况下,您都需要通过在构造函数或上述方法之一中解析 String 来相应地构造实例。
Generally, you'll only want to use the ParamConverter
for third-party classes that you cannot edit.通常,您只想将
ParamConverter
用于您无法编辑的第三方类。 Otherwise use the other three options for your own classes.否则,将其他三个选项用于您自己的类。
From Jersey 2.0, you can use @BeanParam
as input but you must set all @QueryParam
in the DTO variables:从 Jersey 2.0 开始,您可以使用
@BeanParam
作为输入,但必须在 DTO 变量中设置所有@QueryParam
:
@ApiOperation("Save")
@PUT
public Response save(@BeanParam SomeValueDTO inputValue)
{
String prop1 = inputValue.prop1;
String prop2 = inputValue.prop2;
String prop3 = inputValue.prop3;
}
SomeValueDTO.java
will be: SomeValueDTO.java
将是:
public class SomeValueDTO{
@QueryParam("prop1")
public String prop1;
@QueryParam("prop2")
public String prop2;
@QueryParam("prop3")
public String prop3;
}
The http call can be: http 调用可以是:
$http.get('insert-path', {
params: {
prop1: "prop1value",
prop2: "prop2value",
prop3: "prop3value"
}});
Source answer: https://stackoverflow.com/a/17309823/3410465来源答案: https : //stackoverflow.com/a/17309823/3410465
I had the same problem.我有同样的问题。 Just put next in your web.xml
只需将 next 放在您的 web.xml 中
<servlet>
<servlet-name>jersey</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>
org.glassfish.jersey.media.multipart.MultiPartFeature;
org.glassfish.jersey.filter.LoggingFilter
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.