1

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]
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Dino
  • 121
  • 5

1 Answers1

0

I suppose, you need to provide a public no-arg constructor for your SecurityContext implementation.

Yaroslav
  • 118
  • 1
  • 8