media resourcenotfound not suppored怎么解决

随笔 - 895&
评论 - 137&
&&&&&&&&&&&
接上一篇文章讲述处理@RequestMapping的方法参数绑定之后,详细介绍下@RequestBody、@ResponseBody的具体用法和使用时机;同时对曾经看的一篇文章中讲述的某些部分进行澄清 (文章地址:)。
@RequestBody
&&& & i) 该注解用于读取Request请求的body部分数据,使用系统默认配置的HttpMessageConverter进行解析,然后把相应的数据绑定到要返回的对象上;
&&& & ii) 再把HttpMessageConverter返回的对象数据绑定到 controller中方法的参数上。
使用时机:
A) GET、POST方式提时, 根据request header Content-Type的值来判断:
&&& application/x-www-form-urlencoded, 可选(即非必须,因为这种情况的数据@RequestParam, @ModelAttribute也可以处理,当然@RequestBody也能处理);
&&& multipart/form-data, 不能处理(即使用@RequestBody不能处理这种格式的数据);
&&& 其他格式, 必须(其他格式包括application/json, application/xml等。这些格式的数据,必须使用@RequestBody来处理);
B) PUT方式提交时, 根据request header Content-Type的值来判断:
&&& application/x-www-form-urlencoded, 必须;
&&& multipart/form-data, 不能处理;
&&& 其他格式, 必须;
说明:request的body部分的数据编码格式由header部分的Content-Type指定;
@ResponseBody
& & & 该注解用于将Controller的方法返回的对象,通过适当的HttpMessageConverter转换为指定格式后,写入到Response对象的body数据区。
使用时机:
&&&&& 返回的数据不是html标签的页面,而是其他某种格式的数据时(如json、xml等)使用;
HttpMessageConverter
&span style="font-family:Microsoft YaH"&/**
* Strategy interface that specifies a converter that can convert from and to HTTP requests and responses.
* @author Arjen Poutsma
* @author Juergen Hoeller
* @since 3.0
public interface HttpMessageConverter&T& {
* Indicates whether the given class can be read by this converter.
* @param clazz the class to test for readability
* @param mediaType the media type to read, can be {@code null} if not specified.
* Typically the value of a {@code Content-Type} header.
* @return {@code true} {@code false} otherwise
boolean canRead(Class&?& clazz, MediaType mediaType);
* Indicates whether the given class can be written by this converter.
* @param clazz the class to test for writability
* @param mediaType the media type to write, can be {@code null} if not specified.
* Typically the value of an {@code Accept} header.
* @return {@code true} {@code false} otherwise
boolean canWrite(Class&?& clazz, MediaType mediaType);
* Return the list of {@link MediaType} objects supported by this converter.
* @return the list of supported media types
List&MediaType& getSupportedMediaTypes();
* Read an object of the given type form the given input message, and returns it.
* @param clazz the type of object to return. This type must have previously been passed to the
* {@link #canRead canRead} method of this interface, which must have returned {@code true}.
* @param inputMessage the HTTP input message to read from
* @return the converted object
* @throws IOException in case of I/O errors
* @throws HttpMessageNotReadableException in case of conversion errors
T read(Class&? extends T& clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableE
* Write an given object to the given output message.
* @param t the object to write to the output message. The type of this object must have previously been
* passed to the {@link #canWrite canWrite} method of this interface, which must have returned {@code true}.
* @param contentType the content type to use when writing. May be {@code null} to indicate that the
* default content type of the converter must be used. If not {@code null}, this media type must have
* previously been passed to the {@link #canWrite canWrite} method of this interface, which must have
* returned {@code true}.
* @param outputMessage the message to write to
* @throws IOException in case of I/O errors
* @throws HttpMessageNotWritableException in case of conversion errors
void write(T t, MediaType contentType, HttpOutputMessage outputMessage)
throws IOException, HttpMessageNotWritableE
该接口定义了四个方法,分别是读取数据时的 canRead(), read() 和 写入数据时的canWrite(), write()方法。
在使用 &mvc:annotation-driven /&标签配置时,默认配置了RequestMappingHandlerAdapter(注意是RequestMappingHandlerAdapter不是AnnotationMethodHandlerAdapter,详情查看Spring 3.1 document &16.14&Configuring Spring MVC&章节),并为他配置了一下默认的HttpMessageConverter:
ByteArrayHttpMessageConverter converts byte arrays.
StringHttpMessageConverter converts strings.
ResourceHttpMessageConverter converts to/from org.springframework.core.io.Resource for all media types.
SourceHttpMessageConverter converts to/from a javax.xml.transform.Source.
FormHttpMessageConverter converts form data to/from a MultiValueMap&String, String&.
Jaxb2RootElementHttpMessageConverter converts Java objects to/from XML & added if JAXB2 is present on the classpath.
MappingJacksonHttpMessageConverter converts to/from JSON & added if Jackson is present on the classpath.
AtomFeedHttpMessageConverter converts Atom feeds & added if Rome is present on the classpath.
RssChannelHttpMessageConverter converts RSS feeds & added if Rome is present on the classpath.
ByteArrayHttpMessageConverter: 负责读取二进制格式的数据和写出二进制格式的数据;
StringHttpMessageConverter:&& 负责读取字符串格式的数据和写出二进制格式的数据;
ResourceHttpMessageConverter:负责读取资源文件和写出资源文件数据;&
FormHttpMessageConverter:&&&&&& 负责读取form提交的数据(能读取的数据格式为 application/x-www-form-urlencoded,不能读取multipart/form-data格式数据);负责写入application/x-www-from-urlencoded和multipart/form-data格式的数据;
MappingJacksonHttpMessageConverter:& 负责读取和写入json格式的数据;
SouceHttpMessageConverter:&&&&&&&&&&&&&&&&&& 负责读取和写入 xml 中javax.xml.transform.Source定义的数据;
Jaxb2RootElementHttpMessageConverter:& 负责读取和写入xml 标签格式的数据;
AtomFeedHttpMessageConverter:&&&&&&&&&&&&& 负责读取和写入Atom格式的数据;
RssChannelHttpMessageConverter:&&&&&&&&&& 负责读取和写入RSS格式的数据;
当使用@RequestBody和@ResponseBody注解时,RequestMappingHandlerAdapter就使用它们来进行读取或者写入相应格式的数据。
HttpMessageConverter匹配过程:
@RequestBody注解时: 根据Request对象header部分的Content-Type类型,逐一匹配合适的HttpMessageConverter来读取数据;
spring 3.1源代码如下:
private Object readWithMessageConverters(MethodParameter methodParam, HttpInputMessage inputMessage, Class paramType)
throws Exception {
MediaType contentType = inputMessage.getHeaders().getContentType();
if (contentType == null) {
StringBuilder builder = new StringBuilder(ClassUtils.getShortName(methodParam.getParameterType()));
String paramName = methodParam.getParameterName();
if (paramName != null) {
builder.append(' ');
builder.append(paramName);
throw new HttpMediaTypeNotSupportedException(
"Cannot extract parameter (" + builder.toString() + "): no Content-Type found");
List&MediaType& allSupportedMediaTypes = new ArrayList&MediaType&();
if (this.messageConverters != null) {
for (HttpMessageConverter&?& messageConverter : this.messageConverters) {
allSupportedMediaTypes.addAll(messageConverter.getSupportedMediaTypes());
if (messageConverter.canRead(paramType, contentType)) {
if (logger.isDebugEnabled()) {
logger.debug("Reading [" + paramType.getName() + "] as \"" + contentType
+"\" using [" + messageConverter + "]");
return messageConverter.read(paramType, inputMessage);
throw new HttpMediaTypeNotSupportedException(contentType, allSupportedMediaTypes);
@ResponseBody注解时: 根据Request对象header部分的Accept属性(逗号分隔),逐一按accept中的类型,去遍历找到能处理的HttpMessageConverter;
源代码如下:
private void writeWithMessageConverters(Object returnValue,
HttpInputMessage inputMessage, HttpOutputMessage outputMessage)
throws IOException, HttpMediaTypeNotAcceptableException {
List&MediaType& acceptedMediaTypes = inputMessage.getHeaders().getAccept();
if (acceptedMediaTypes.isEmpty()) {
acceptedMediaTypes = Collections.singletonList(MediaType.ALL);
MediaType.sortByQualityValue(acceptedMediaTypes);
Class&?& returnValueType = returnValue.getClass();
List&MediaType& allSupportedMediaTypes = new ArrayList&MediaType&();
if (getMessageConverters() != null) {
for (MediaType acceptedMediaType : acceptedMediaTypes) {
for (HttpMessageConverter messageConverter : getMessageConverters()) {
if (messageConverter.canWrite(returnValueType, acceptedMediaType)) {
messageConverter.write(returnValue, acceptedMediaType, outputMessage);
if (logger.isDebugEnabled()) {
MediaType contentType = outputMessage.getHeaders().getContentType();
if (contentType == null) {
contentType = acceptedMediaT
logger.debug("Written [" + returnValue + "] as \"" + contentType +
"\" using [" + messageConverter + "]");
this.responseArgumentUsed = true;
for (HttpMessageConverter messageConverter : messageConverters) {
allSupportedMediaTypes.addAll(messageConverter.getSupportedMediaTypes());
throw new HttpMediaTypeNotAcceptableException(allSupportedMediaTypes);
MappingJacksonHttpMessageConverter 调用了 objectMapper.writeValue(OutputStream stream, Object)方法,使用@ResponseBody注解返回的对象就传入Object参数内。若返回的对象为已经格式化好的json串时,不使用@RequestBody注解,而应该这样处理:
1、response.setContentType("application/ charset=UTF-8");
2、response.getWriter().print(jsonStr);
直接输出到body区,然后的视图为void。
参考资料:
1、 Spring 3.1 Doc:&
spring-3.1.0/docs/spring-framework-reference/html/mvc.html
2、Spring 3.x MVC 入门4 -- @ResponseBody & @RequestBody
阅读(...) 评论()Windows Media PlayerQ:How can I play DVDs with Windows Media Player?A:To play DVDs in Windows Media Player you need a MPEG-2 decoder that is capable of decoding DVD video and is also compatible with WMP. The K-Lite Codec Pack contains a compatible decoder for Windows XP/Vista/7.On Windows 8 and 8.1 you can only plays DVDs in WMP if you install the Media Center add-on from Microsoft. This is not a matter of missing codecs, so you can't solve it by installing any codecs! Microsoft has intentially disabled this functionality until you upgrade your Windows license.Windows 10 doesn't not provide any DVD playback ability in WMP, and this can't be fixed by installing additional codecs.DVD playback will work normally on any version of Windows in other players, such as Media Player Classic and VLC.Q:WMV HD videos play slow and without sound in Windows Media PlayerA:If one or more of the following filters is installed on your computer, then disable or uninstall them:- Matrix Mixer - Morgan Multimedia Stream Switcher - DC-DSPSlow response when seeking certain WMV videos is another common problem. That is not caused by specific codecs, but is due to limitations of the Windows Media container format. A solution could be to remux the video into another container format, such as Matroska (.mkv). A free tool for that is .Q:I get the following error message when trying to play a DVD: &Windows Media Player cannot play DVD video. You might need to adjust your Windows display settings. Open display settings in Control Panel, and then try lowering your screen resolution and color quality settings.&A:This is a generic error message that WMP displays when it fails to play a DVD. Ignore the remark about display settings and resolution. Those usually have nothing to do with the actual cause of the problem.This error message is usually displayed when there is no MPEG-2 video decoder installed that is compatible with WMP. Another cause can be a buggy or old graphics driver.The K-Lite Codec Pack contains a compatible decoder. Make sure you have that enabled during installation of the pack.Q:Why isn't ffdshow getting used by WMP and WMC on Windows 7?A:Windows 7 comes bundled with decoders for several video formats, including H.264 and Xvid. These decoders from Microsoft are used by default by most DirectShow applications, including Windows Media Player and Media Center.If you prefer using LAV Video decoder, ffdshow, or some other third party decoder, then you can use Codec Tweak Tool to adjust the preferred decoder settings in Windows 7. This tool is included with the K-Lite Codec Pack and is also available as a standalone application.The K-Lite Codec Pack automatically adjusts the preferred codecs settings for the most common video formats. It uses specials settings to make Windows select the decoder based on the filter merit. This is similar to how things work on older Windows versions.Sometimes it is also needed to disable the Microsoft audio and video decoders.The Microsoft players use the new Media Foundation playback framework for playing certain file types, such as AVI, MP4, M4V, MOV, M2TS, and WMV. To force the use of DirectShow filters, you may also need to disable Media Foundation with the Codec tweak Tool.Q:Some videos play very pixelated on Windows 7A:This is a bug in your graphics driver. Updating the driver usually fixes this problem.Possible workarounds: Codec Tweak Tool & Various Tweaks & disable DXVA hardware acceleration
Codec Tweak Tool & Win7DSFilterTweaker & MS Codec Tweaks & Disable the Microsoft DTV-DVD Video DecoderQ:I am unable to seek within .ts files with WMP12A:Codec Tweak Tool & Win7DSFilterTweaker & MS Codec Tweaks & Disable Media FoundationQ:.m2ts files that contain VC-1 video do not play with WMP12A:Codec Tweak Tool & Win7DSFilterTweaker & MS Codec Tweaks & Disable Media FoundationQ:AVI files that contain AC3 audio give noise in WMP12A:Codec Tweak Tool & Win7DSFilterTweaker & MS Codec Tweaks & Disable the Microsoft DTV-DVD Audio DecoderQ:I am unable to seek within files when played from the WMP libraryA:This is a bug in WMP. It may happen with any file type that WMP does not support natively.There are two workarounds:Play the file by clicking on it in Windows Explorer instead of opening it through the WMP library. Add the file to a playlist in the library. When played from a playlist, the duration of the file is shown correctly and seeking works normally. Note that with a playlist we mean an actual saved playlist, not the Now Playing list of WMP.&&QMediaResource Class | Qt Multimedia 5.9
QMediaResource
QMediaResource Class
class provides a description of a media resource.
Header: #include &QMediaResource&
qmake: QT += multimedia
Public Functions
(const QUrl &url, const QString &mimeType = QString())
(const QNetworkRequest &request, const QString &mimeType = QString())
(const QMediaResource &other)
int () const
QString () const
int () const
qint64 () const
bool () const
QString () const
QString () const
QNetworkRequest () const
QSize () const
int () const
void (int rate)
void (const QString &codec)
void (int channels)
void (const qint64 size)
void (const QString &language)
void (const QSize &resolution)
void (int width, int height)
void (int sampleRate)
void (int rate)
void (const QString &codec)
QUrl () const
int () const
QString () const
bool (const QMediaResource &other) const
QMediaResource &(const QMediaResource &other)
bool (const QMediaResource &other) const
Related Non-Members
Detailed Description
class provides a description of a media resource.
A media resource is composed of a
containing the location of the resource and a set of properties that describe the format of the resource. The properties provide a means to assess a resource without first attempting to load it, and in situations where media be represented by multiple alternative representations provide a means to select the appropriate resource.
Media made available by a remote services can often be available in multiple encodings or quality levels, this allows a client to select an appropriate resource based on considerations such as codecs supported, network bandwidth, and display constraints.
includes information such as the ,
bit rates, and
so these constraints and others can be evaluated.
The only mandatory property of a
is the ().
See also .
Member Function Documentation
QMediaResource::QMediaResource()
Constructs a null media resource.
QMediaResource::QMediaResource(const
&url, const
&mimeType = QString())
Constructs a media resource with the given mimeType from a url.
QMediaResource::QMediaResource(const
&request, const
&mimeType = QString())
Constructs a media resource with the given mimeType from a network request.
QMediaResource::QMediaResource(const
Constructs a copy of a media resource other.
QMediaResource::~QMediaResource()
Destroys a media resource.
int QMediaResource::audioBitRate() const
Returns the bit rate in bits per second of a media resource's audio stream.
This may be zero if the bit rate is unknown, or the resource contains no audio stream.
See also ().
QMediaResource::audioCodec() const
Returns the audio codec of a media resource.
This may be null if the media resource does not contain an audio stream, or the codec is unknown.
See also ().
int QMediaResource::channelCount() const
Returns the number of audio channels in a media resource.
This may be zero if the sample size is unknown, or the resource contains no audio stream.
See also ().
QMediaResource::dataSize() const
Returns the size in bytes of a media resource.
This may be zero if the size is unknown.
See also ().
bool QMediaResource::isNull() const
Identifies if a media resource is null.
Returns true if the resource is null, and false otherwise.
QMediaResource::language() const
Returns the language of a media resource as an ISO 639-2 code.
This may be null if the language is unknown.
See also ().
QMediaResource::mimeType() const
Returns the MIME type of a media resource.
This may be null if the MIME type is unknown.
QMediaResource::request() const
Returns the network request associated with this media resource.
QMediaResource::resolution() const
Returns the resolution in pixels of a media resource.
This may be null is the resolution is unknown, or the resource contains no pixel data (i.e. the resource is an audio stream.
See also ().
int QMediaResource::sampleRate() const
Returns the audio sample rate of a media resource.
This may be zero if the sample size is unknown, or the resource contains no audio stream.
See also ().
void QMediaResource::setAudioBitRate(int rate)
Sets the bit rate in bits per second of a media resource's video stream.
See also ().
void QMediaResource::setAudioCodec(const
Sets the audio codec of a media resource.
See also ().
void QMediaResource::setChannelCount(int channels)
Sets the number of audio channels in a media resource.
See also ().
void QMediaResource::setDataSize(const
Sets the size in bytes of a media resource.
See also ().
void QMediaResource::setLanguage(const
&language)
Sets the language of a media resource.
See also ().
void QMediaResource::setResolution(const
&resolution)
Sets the resolution in pixels of a media resource.
See also ().
void QMediaResource::setResolution(int width, int height)
Sets the width and height in pixels of a media resource.
void QMediaResource::setSampleRate(int sampleRate)
Sets the audio sampleRate of a media resource.
See also ().
void QMediaResource::setVideoBitRate(int rate)
Sets the bit rate in bits per second of a media resource's video stream.
See also ().
void QMediaResource::setVideoCodec(const
Sets the video codec of media resource.
See also ().
QMediaResource::url() const
Returns the URL of a media resource.
int QMediaResource::videoBitRate() const
Returns the bit rate in bits per second of a media resource's video stream.
This may be zero if the bit rate is unknown, or the resource contains no video stream.
See also ().
QMediaResource::videoCodec() const
Returns the video codec of a media resource.
This may be null if the media resource does not contain a video stream, or the codec is unknonwn.
See also ().
bool QMediaResource::operator!=(const
&other) const
Compares a media resource to other.
Returns true if they are different, and false otherwise.
&QMediaResource::operator=(const
Assigns the value of other to a media resource.
bool QMediaResource::operator==(const
&other) const
Compares a media resource to other.
Returns true if the resources are identical, and false otherwise.
Related Non-Members
typedef QMediaResourceList
Synonym for QList&QMediaResource&
& 2017 The Qt Company Ltd.
Documentation contributions included herein are the copyrights of
their respective owners.
The documentation provided herein is licensed under the terms of the
as published by the Free Software Foundation.
Qt and respective logos are trademarks of The Qt Company Ltd.
in Finland and/or other countries worldwide. All other trademarks are property
of their respective owners.

我要回帖

更多关于 not enough resource 的文章

 

随机推荐