简体   繁体   中英

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

I have problem with SecurityContext from javax.ws.rs.

In my controller I inject SecurityContext with annotation @Context.

@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";

}

In pom.xml I added dependecy:

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

But when I try to hit this API I got error:

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 实现提供一个公共的无参数构造函数。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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