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

时间:2019-01-30 13:03:34

标签: java security security-context

我在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中,我添加了dependecy:

<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]

1 个答案:

答案 0 :(得分:0)

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