繁体   English   中英

错误 找不到接口 javax.ws.rs.core.SecurityContext 的主要或默认构造函数

[英]Error No primary or default constructor found for interface javax.ws.rs.core.SecurityContext

我对 javax.ws.rs 的 SecurityContext 有问题。

在我的控制器中,我注入了带有注释 @Context 的 SecurityContext。

@RequestMapping(value = "/movie/search")
public String getMovies(@RequestParam(name = "search") String search, Model model, @Context SecurityContext securityContext) throws IOException {
    String token = s.getToken(securityContext);
    String res = s.getMovies(search,token);
    List<Movie> movies = parser.JsonToObject(res);
    model.addAttribute("movies", movies);
    return "movieList";

}

在 pom.xml 我添加了依赖:

<dependency>
        <groupId>javax.ws.rs</groupId>
        <artifactId>javax.ws.rs-api</artifactId>
        <version>2.0</version>
    </dependency>

但是当我尝试点击这个 API 时,我得到了错误:

java.lang.NoSuchMethodException: javax.ws.rs.core.SecurityContext.<init>()
at java.lang.Class.getConstructor0(Unknown Source) ~[na:1.8.0_201]
at java.lang.Class.getDeclaredConstructor(Unknown Source) ~[na:1.8.0_201]
at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.createAttribute(ModelAttributeMethodProcessor.java:208) ~[spring-web-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor.createAttribute(ServletModelAttributeMethodProcessor.java:84) ~[spring-webmvc-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:131) ~[spring-web-5.0.12.RELEASE.jar:5.0.12.RELEASE]

我想,您需要为您的 SecurityContext 实现提供一个公共的无参数构造函数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM