英文:
can't import org.springframework.data.rest.webmvc.ResourceNotFoundException;
问题
我无法提供代码的翻译,但以下是您提供的英文文本的中文翻译:
"我一直无法导入以下库以用于处理一些错误。我一直在互联网上寻找有关这个问题的信息,但没有成功。是不是我需要下载一个特定的.jar文件?如果是这样,我将感谢您告诉我如何做。我对这个网络和Spring的东西还不太了解。"
"代码:"
package org.magnum.dataup;
import java.io.IOException;
import java.io.OutputStream;
import java.util.*;
import java.util.concurrent.atomic.AtomicLong;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.magnum.dataup.model.Video;
import org.magnum.dataup.model.VideoStatus;
import org.magnum.dataup.model.VideoStatus.VideoState;
import org.eclipse.jetty.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
@Controller
public class VideoController {
public static final String VIDEO_SVC_PATH = "/video";
public static final String VIDEO_DATA_PATH = VIDEO_SVC_PATH + "/{id}/data";
private static final AtomicLong currentId = new AtomicLong(0L);
private Map<Long, Video> videos = new HashMap<Long, Video>();
@RequestMapping(value = VIDEO_SVC_PATH, method = RequestMethod.GET)
public @ResponseBody Collection<Video> getVideoList() {
return videos.values();
}
@RequestMapping(value = VIDEO_DATA_PATH, method = RequestMethod.GET)
public void getData(@PathVariable("id") long id, HttpServletResponse response)
throws IOException {
VideoFileManager videoData = VideoFileManager.get();
try {
videoData.copyVideoData(videos.get(id), response.getOutputStream());
} catch (Exception e) {
throw new ResourceNotFoundException();
}
}
@RequestMapping(value = VIDEO_SVC_PATH, method = RequestMethod.POST)
public @ResponseBody Video addVideoMetadata(@RequestBody Video v, HttpServletRequest request)
throws IOException {
v.setId(currentId.incrementAndGet());
v.setDataUrl(getUrlBaseForLocalServer(request) + "/" + VIDEO_SVC_PATH + v.getId() + "/data");
videos.put(v.getId(), v);
return v;
}
@RequestMapping(value = VIDEO_DATA_PATH, method = RequestMethod.POST)
public @ResponseBody VideoStatus addVideoData(@PathVariable("id") long id,
@RequestParam MultipartFile data) throws IOException {
VideoFileManager videoData = VideoFileManager.get();
try {
videoData.saveVideoData(videos.get(id), data.getInputStream());
} catch (Exception e) {
throw new ResourceNotFoundException();
}
return new VideoStatus(VideoState.READY);
}
private String getUrlBaseForLocalServer(HttpServletRequest request) {
String baseURL = "http://" + request.getServerName()
+ ((request.getServerPort() != 80) ? ":" + request.getServerPort() : "");
return baseURL;
}
}
导入时的错误消息:
提前感谢您的帮助。
英文:
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:
package org.magnum.dataup;
import java.io.IOException;
import java.io.OutputStream;
import java.util.*;
import java.util.concurrent.atomic.AtomicLong;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.magnum.dataup.model.Video;
import org.magnum.dataup.model.VideoStatus;
import org.magnum.dataup.model.VideoStatus.VideoState;
import org.eclipse.jetty.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
@Controller
public class VideoController {
public static final String VIDEO_SVC_PATH = "/video";
public static final String VIDEO_DATA_PATH = VIDEO_SVC_PATH + "/{id}/data";
private static final AtomicLong currentId = new AtomicLong(0L);
private Map<Long, Video> videos = new HashMap<Long, Video>();
@RequestMapping(value = VIDEO_SVC_PATH, method = RequestMethod.GET)
public @ResponseBody Collection<Video> getVideoList() {
return videos.values();
}
@RequestMapping(value = VIDEO_DATA_PATH, method = RequestMethod.GET)
public void getData(@PathVariable("id") long id, HttpServletResponse response)
throws IOException {
VideoFileManager videoData = VideoFileManager.get();
try {
videoData.copyVideoData(videos.get(id), response.getOutputStream());
} catch (Exception e) {
throw new ResourceNotFoundException();
}
}
@RequestMapping(value = VIDEO_SVC_PATH, method = RequestMethod.POST)
public @ResponseBody Video addVideoMetadata(@RequestBody Video v, HttpServletRequest request)
throws IOException {
v.setId(currentId.incrementAndGet());
v.setDataUrl(getUrlBaseForLocalServer(request) + "/" + VIDEO_SVC_PATH + v.getId() + "/data");
videos.put(v.getId(), v);
return v;
}
@RequestMapping(value = VIDEO_DATA_PATH, method = RequestMethod.POST)
public @ResponseBody VideoStatus addVideoData(@PathVariable("id") long id,
@RequestParam MultipartFile data) throws IOException {
VideoFileManager videoData = VideoFileManager.get();
try {
videoData.saveVideoData(videos.get(id), data.getInputStream());
} catch (Exception e) {
throw new ResourceNotFoundException();
}
return new VideoStatus(VideoState.READY);
}
private String getUrlBaseForLocalServer(HttpServletRequest request) {
String baseURL = "http://" + request.getServerName()
+ ((request.getServerPort() != 80) ? ":" + request.getServerPort() : "");
return baseURL;
}
}
Error Message when importing:
Thanks in advance
答案1
得分: 0
你正在寻找的JAR文件可以从Maven仓库这里获取。
如果您使用Maven进行依赖管理,只需将以下内容添加到您的pom.xml文件中:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-webmvc</artifactId>
<version>3.3.3.RELEASE</version>
</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
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-webmvc</artifactId>
<version>3.3.3.RELEASE</version>
</dependency>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论