我对来自 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]