Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
6b83e0ad
Commit
6b83e0ad
authored
Mar 05, 2014
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change bean name of ContentNegotiatingViewResolver
Fixed gh-428
parent
15372cb7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
16 deletions
+27
-16
howto.md
docs/howto.md
+23
-14
WebMvcAutoConfiguration.java
...ework/boot/autoconfigure/web/WebMvcAutoConfiguration.java
+4
-2
No files found.
docs/howto.md
View file @
6b83e0ad
...
@@ -557,24 +557,33 @@ servlet context (defaults are both empty, but accessible for external
...
@@ -557,24 +557,33 @@ servlet context (defaults are both empty, but accessible for external
configuration via
`spring.view.prefix`
and
`spring.view.suffix`
). It
configuration via
`spring.view.prefix`
and
`spring.view.suffix`
). It
can be overridden by providing a bean of the same type.
can be overridden by providing a bean of the same type.
*
A
`BeanNameViewResolver`
with id "beanNameViewResolver". This is a
*
A
`BeanNameViewResolver`
with id "beanNameViewResolver" is added if
useful member of the view resolver chain and will pick up any beans
there are beans of type
`View`
. This is a useful member of the view
with the same name as the
`View`
being resolved. It can be overridden
resolver chain and will pick up any beans with the same name as the
by providing a bean of the same type, but it's unlikely you will need
`View`
being resolved. It can be overridden by providing a bean of the
to do that.
same type, but it's unlikely you will need to do that.
*
A
`ContentNegotiatingViewResolver`
with id "viewResolver" is only
*
A
`ContentNegotiatingViewResolver`
with id
added if there
*are*
actually beans of type
`View`
present. This is a
"contentNegotiatingViewResolver" is only added if there are already
"master" resolver, delegating to all the others and attempting to find
beans of type
`ViewResolver`
present. This is a "master" resolver,
a match to the "Accept" HTTP header sent by the client. There is a
delegating to all the others and attempting to find a match to the
useful
"Accept" HTTP header sent by the client, so it is added with highest
precedence (it is always consulted bythe
`DispatcherServlet`
). There
is a useful
[
blog about `ContentNegotiatingViewResolver`
](
https://spring.io/blog/2013/06/03/content-negotiation-using-views
)
[
blog about `ContentNegotiatingViewResolver`
](
https://spring.io/blog/2013/06/03/content-negotiation-using-views
)
that you might like to study to learn more, and also look at the
that you might like to study to learn more, and also look at the
source code for detail.
source code for detail.
Be careful not to define your own `ViewResolver` with id
Bear in mind that any custom `ViewResolvers` that you add to your
"viewResolver" (like the
`ContentNegotiatingViewResolver`
) otherwise,
own application will be consulted by the
in that case, your bean will be ovewritten, not the other way round.
`ContentNegotiatingViewResolver`
, so make sure they yield
`View`
instances that give accurate responses in their
`getContentType()`
method.
Also be careful not to define your own `ViewResolver` with id
"contentNegotiatingViewResolver" (like the
`ContentNegotiatingViewResolver`
) otherwise, in that case, your bean
will be ovewritten, not the other way round.
*
If you use Thymeleaf you will also have a
`ThymeleafViewResolver`
*
If you use Thymeleaf you will also have a
`ThymeleafViewResolver`
with id "thymeleafViewResolver". It looks for resources by surrounding
with id "thymeleafViewResolver". It looks for resources by surrounding
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java
View file @
6b83e0ad
...
@@ -54,6 +54,7 @@ import org.springframework.web.context.request.RequestContextListener;
...
@@ -54,6 +54,7 @@ import org.springframework.web.context.request.RequestContextListener;
import
org.springframework.web.filter.HiddenHttpMethodFilter
;
import
org.springframework.web.filter.HiddenHttpMethodFilter
;
import
org.springframework.web.servlet.DispatcherServlet
;
import
org.springframework.web.servlet.DispatcherServlet
;
import
org.springframework.web.servlet.View
;
import
org.springframework.web.servlet.View
;
import
org.springframework.web.servlet.ViewResolver
;
import
org.springframework.web.servlet.config.annotation.EnableWebMvc
;
import
org.springframework.web.servlet.config.annotation.EnableWebMvc
;
import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
;
import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
;
import
org.springframework.web.servlet.config.annotation.ViewControllerRegistry
;
import
org.springframework.web.servlet.config.annotation.ViewControllerRegistry
;
...
@@ -177,8 +178,9 @@ public class WebMvcAutoConfiguration {
...
@@ -177,8 +178,9 @@ public class WebMvcAutoConfiguration {
}
}
@Bean
@Bean
@ConditionalOnBean
(
View
.
class
)
@ConditionalOnBean
(
ViewResolver
.
class
)
public
ContentNegotiatingViewResolver
viewResolver
(
BeanFactory
beanFactory
)
{
public
ContentNegotiatingViewResolver
contentNegotiatingViewResolver
(
BeanFactory
beanFactory
)
{
ContentNegotiatingViewResolver
resolver
=
new
ContentNegotiatingViewResolver
();
ContentNegotiatingViewResolver
resolver
=
new
ContentNegotiatingViewResolver
();
resolver
.
setContentNegotiationManager
(
beanFactory
resolver
.
setContentNegotiationManager
(
beanFactory
.
getBean
(
ContentNegotiationManager
.
class
));
.
getBean
(
ContentNegotiationManager
.
class
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment