Upgrade BeanNameViewResolver to support XML and Java Config bean definitions [SPR-14022] #18594
Labels
in: web
Issues in web modules (web, webmvc, webflux, websocket)
status: declined
A suggestion or change that we don't feel we should currently apply
type: enhancement
A general enhancement
Paul Chapman opened SPR-14022 and commented
Currently the
BeanNameViewResolver
supports finding beans by name from the sameApplicationContext
that it is defined in. This can lead to lots ofView
beans in the context that only theBeanNameViewResolver
needs to know about. It also means that a given view name can only be resolved to a single View bean. If I have a PDF generating bean and an Excel generating bean I can't use this approach.The
XmlViewResolver
solves this problem by allowing the View beans to be specified in a dedicated bean XML file, just for the View beans, reducing bean-clutter. By having two such resolvers I can have two view Beans with the same name. But, as the name implies, this resolver only supports beans defined using XML.I propose enhancing the
BeanNameViewResolver
to optionally support both beans defined in XML files and/or in dedicated Java Configurations. This enhancement would make theXmlViewResolver
obsolete.I anticipate something like this:
I would expect
BeanNameViewResolver
to provide both constructors andsetLocation()
methods that take an array of Resource (for XML bean files) or an array of@Configuration
classes.The default behaviour of the
BeanNameViewResolver
can remain the same to ensure backwards compatibility.The
ViewResolverRegistry
should be enhanced similarly to providebeanName(Resource ...)
andbeanName(Class<?>...)
.And the equivalent change to
<mvc:resolvers>
.Reference URL: #987
The text was updated successfully, but these errors were encountered: