无法导入org.springframework.data.rest.webmvc.ResourceNotFoundException;

huangapple go评论113阅读模式
英文:

can't import org.springframework.data.rest.webmvc.ResourceNotFoundException;

问题

我无法提供代码的翻译,但以下是您提供的英文文本的中文翻译:

"我一直无法导入以下库以用于处理一些错误。我一直在互联网上寻找有关这个问题的信息,但没有成功。是不是我需要下载一个特定的.jar文件?如果是这样,我将感谢您告诉我如何做。我对这个网络和Spring的东西还不太了解。"

"代码:"

  1. package org.magnum.dataup;
  2. import java.io.IOException;
  3. import java.io.OutputStream;
  4. import java.util.*;
  5. import java.util.concurrent.atomic.AtomicLong;
  6. import javax.servlet.http.HttpServletRequest;
  7. import javax.servlet.http.HttpServletResponse;
  8. import org.magnum.dataup.model.Video;
  9. import org.magnum.dataup.model.VideoStatus;
  10. import org.magnum.dataup.model.VideoStatus.VideoState;
  11. import org.eclipse.jetty.http.HttpStatus;
  12. import org.springframework.stereotype.Controller;
  13. import org.springframework.web.bind.annotation.PathVariable;
  14. import org.springframework.web.bind.annotation.RequestBody;
  15. import org.springframework.web.bind.annotation.RequestMapping;
  16. import org.springframework.web.bind.annotation.RequestMethod;
  17. import org.springframework.web.bind.annotation.RequestParam;
  18. import org.springframework.web.bind.annotation.ResponseBody;
  19. import org.springframework.web.multipart.MultipartFile;
  20. import org.springframework.data.rest.webmvc.ResourceNotFoundException;
  21. @Controller
  22. public class VideoController {
  23. public static final String VIDEO_SVC_PATH = "/video";
  24. public static final String VIDEO_DATA_PATH = VIDEO_SVC_PATH + "/{id}/data";
  25. private static final AtomicLong currentId = new AtomicLong(0L);
  26. private Map<Long, Video> videos = new HashMap<Long, Video>();
  27. @RequestMapping(value = VIDEO_SVC_PATH, method = RequestMethod.GET)
  28. public @ResponseBody Collection<Video> getVideoList() {
  29. return videos.values();
  30. }
  31. @RequestMapping(value = VIDEO_DATA_PATH, method = RequestMethod.GET)
  32. public void getData(@PathVariable("id") long id, HttpServletResponse response)
  33. throws IOException {
  34. VideoFileManager videoData = VideoFileManager.get();
  35. try {
  36. videoData.copyVideoData(videos.get(id), response.getOutputStream());
  37. } catch (Exception e) {
  38. throw new ResourceNotFoundException();
  39. }
  40. }
  41. @RequestMapping(value = VIDEO_SVC_PATH, method = RequestMethod.POST)
  42. public @ResponseBody Video addVideoMetadata(@RequestBody Video v, HttpServletRequest request)
  43. throws IOException {
  44. v.setId(currentId.incrementAndGet());
  45. v.setDataUrl(getUrlBaseForLocalServer(request) + "/" + VIDEO_SVC_PATH + v.getId() + "/data");
  46. videos.put(v.getId(), v);
  47. return v;
  48. }
  49. @RequestMapping(value = VIDEO_DATA_PATH, method = RequestMethod.POST)
  50. public @ResponseBody VideoStatus addVideoData(@PathVariable("id") long id,
  51. @RequestParam MultipartFile data) throws IOException {
  52. VideoFileManager videoData = VideoFileManager.get();
  53. try {
  54. videoData.saveVideoData(videos.get(id), data.getInputStream());
  55. } catch (Exception e) {
  56. throw new ResourceNotFoundException();
  57. }
  58. return new VideoStatus(VideoState.READY);
  59. }
  60. private String getUrlBaseForLocalServer(HttpServletRequest request) {
  61. String baseURL = "http://" + request.getServerName()
  62. + ((request.getServerPort() != 80) ? ":" + request.getServerPort() : "");
  63. return baseURL;
  64. }
  65. }

导入时的错误消息:

无法导入org.springframework.data.rest.webmvc.ResourceNotFoundException;

提前感谢您的帮助。

英文:

I haven not being able to import the following library to use it for handling some error. I have been looking up on internet about this problem but cannot succeed. Is it that i have to download an specific .jar? if so, I would appreciate the help to know how to do it. I am pretty new into this web and spring stuff.

Code:

  1. package org.magnum.dataup;
  2. import java.io.IOException;
  3. import java.io.OutputStream;
  4. import java.util.*;
  5. import java.util.concurrent.atomic.AtomicLong;
  6. import javax.servlet.http.HttpServletRequest;
  7. import javax.servlet.http.HttpServletResponse;
  8. import org.magnum.dataup.model.Video;
  9. import org.magnum.dataup.model.VideoStatus;
  10. import org.magnum.dataup.model.VideoStatus.VideoState;
  11. import org.eclipse.jetty.http.HttpStatus;
  12. import org.springframework.stereotype.Controller;
  13. import org.springframework.web.bind.annotation.PathVariable;
  14. import org.springframework.web.bind.annotation.RequestBody;
  15. import org.springframework.web.bind.annotation.RequestMapping;
  16. import org.springframework.web.bind.annotation.RequestMethod;
  17. import org.springframework.web.bind.annotation.RequestParam;
  18. import org.springframework.web.bind.annotation.ResponseBody;
  19. import org.springframework.web.multipart.MultipartFile;
  20. import org.springframework.data.rest.webmvc.ResourceNotFoundException;
  21. @Controller
  22. public class VideoController {
  23. public static final String VIDEO_SVC_PATH = &quot;/video&quot;;
  24. public static final String VIDEO_DATA_PATH = VIDEO_SVC_PATH + &quot;/{id}/data&quot;;
  25. private static final AtomicLong currentId = new AtomicLong(0L);
  26. private Map&lt;Long, Video&gt; videos = new HashMap&lt;Long, Video&gt;();
  27. @RequestMapping(value = VIDEO_SVC_PATH, method = RequestMethod.GET)
  28. public @ResponseBody Collection&lt;Video&gt; getVideoList() {
  29. return videos.values();
  30. }
  31. @RequestMapping(value = VIDEO_DATA_PATH, method = RequestMethod.GET)
  32. public void getData(@PathVariable(&quot;id&quot;) long id, HttpServletResponse response)
  33. throws IOException {
  34. VideoFileManager videoData = VideoFileManager.get();
  35. try {
  36. videoData.copyVideoData(videos.get(id), response.getOutputStream());
  37. } catch (Exception e) {
  38. throw new ResourceNotFoundException();
  39. }
  40. }
  41. @RequestMapping(value = VIDEO_SVC_PATH, method = RequestMethod.POST)
  42. public @ResponseBody Video addVideoMetadata(@RequestBody Video v, HttpServletRequest request)
  43. throws IOException {
  44. v.setId(currentId.incrementAndGet());
  45. v.setDataUrl(getUrlBaseForLocalServer(request) + &quot;/&quot; + VIDEO_SVC_PATH + v.getId() + &quot;/data&quot;);
  46. videos.put(v.getId(), v);
  47. return v;
  48. }
  49. @RequestMapping(value = VIDEO_DATA_PATH, method = RequestMethod.POST)
  50. public @ResponseBody VideoStatus addVideoData(@PathVariable(&quot;id&quot;) long id,
  51. @RequestParam MultipartFile data) throws IOException {
  52. VideoFileManager videoData = VideoFileManager.get();
  53. try {
  54. videoData.saveVideoData(videos.get(id), data.getInputStream());
  55. } catch (Exception e) {
  56. throw new ResourceNotFoundException();
  57. }
  58. return new VideoStatus(VideoState.READY);
  59. }
  60. private String getUrlBaseForLocalServer(HttpServletRequest request) {
  61. String baseURL = &quot;http://&quot; + request.getServerName()
  62. + ((request.getServerPort() != 80) ? &quot;:&quot; + request.getServerPort() : &quot;&quot;);
  63. return baseURL;
  64. }
  65. }

Error Message when importing:

无法导入org.springframework.data.rest.webmvc.ResourceNotFoundException;

Thanks in advance

答案1

得分: 0

你正在寻找的JAR文件可以从Maven仓库这里获取。

如果您使用Maven进行依赖管理,只需将以下内容添加到您的pom.xml文件中:

  1. <dependency>
  2. <groupId>org.springframework.data</groupId>
  3. <artifactId>spring-data-rest-webmvc</artifactId>
  4. <version>3.3.3.RELEASE</version>
  5. </dependency>
英文:

The jar you looking for is available from maven repo here .

If you use maven for dependency management just add this to your pom.xml

  1. &lt;dependency&gt;
  2. &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
  3. &lt;artifactId&gt;spring-data-rest-webmvc&lt;/artifactId&gt;
  4. &lt;version&gt;3.3.3.RELEASE&lt;/version&gt;
  5. &lt;/dependency&gt;

huangapple
  • 本文由 发表于 2020年8月14日 05:30:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/63403480.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定