New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose path-related request mapping settings in the MVC XML namespace [SPR-10163] #14796

Closed
spring-issuemaster opened this Issue Jan 11, 2013 · 8 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

spring-issuemaster commented Jan 11, 2013

Michael Osipov opened SPR-10163 and commented

There is at the moment no easy way to modify RequestMappingHandlerMapping's setters. Namely, I had to set setUseSuffixPatternMatch(false). mvc:annotation-driven does not allow to change this bean. There is a Java equivalent

@Configuration
public class WebConfig extends WebMvcConfigurationSupport {

  @Override
  @Bean
  public RequestMappingHandlerMapping requestMappingHandlerMapping() {
    RequestMappingHandlerMapping hm = super.requestMappingHandlerMapping();
    hm.setSuffixPatternMatch(false);
    return hm;
  }
}

Which does not really work if you mix XML and Java config because this class is called when all URL handlers have been already registered.

I have found issue #14007 which solves the problem but is somewhat tedious in implementation.

Can we have mvc:annotation-driven extended in such a way that exactly such such can be done in XML?

If this does not require any extension please add a doc chapter which shows how to do this with XML. There are only examples in Java whether it's the Spring Docs or Stackoverflow.

Something like this should work too:

<beans:bean 
class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" p:order="0" p:useSuffixPatternMatch="false" />

Which actually doesn't!

Another reference: http://forum.springsource.org/showthread.php?120192


Affects: 3.1.3

Issue Links:

  • #15878 Allow configuring RequestMappingHandlerMapping in mvc:annotation-driven ("is duplicated by")
  • #18757 Backport MVC config path config options to 3.2.x
  • #16111 Expose path-related request mapping settings in the MVC Java config

Referenced from: commits eac4881, 96b418c, fc05df0, 8edb7a1, 80a16c6

9 votes, 10 watchers

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Feb 8, 2013

Rossen Stoyanchev commented

For what it's worth the documentation does have such a section. That said it could be easier. This would probably work as an override:

<mvc:annotation-driven>
    <mvc:handler-mapping>
        <ref bean="handlerMapping" />
    </mvc:handler-mapping>
</mvc:annotation-driven>

<bean id="handlerMapping" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
    <property name="useSuffixPatternMatch" value="false" />
    <property name="useTrailingSlashMatch" value="false" />
</bean>
@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Feb 8, 2013

Michael Osipov commented

If you are referring to chapter 17.15.10, I have implemented a BeanPostProcessor. No word mentioned about XML config. Your approach sounds reasonable. This is exactly what I would expect. Additionally, this should not change the order of the HandlerMappings of course in any way. It should be equivalent to the approach with the BeanPostProcessor.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Mar 29, 2013

Anthony Gerrard commented

If you're defining your own interceptors using <mvc:interceptors /> then none of the workarounds here are of much use.

What is really needed is a way to set properties of the RequestMappingHandlerMapping created in WebMvcConfigurationSupport.requestMappingHandlerMapping from the XML. I'd like to set removeSemicolonContent=true.

Alternatively have a way of specifying a RequestMappingHandlerMapping for this method to use (and inject interceptors and a ContentNegotiationManager into)

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Dec 24, 2013

not-three commented

I use RequestMappingHandlerAdapter instead of mvc:annotation-driven, and it works. But I still like this Improvement, keep watching.

	<bean
		class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter" />
	<bean
		class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
		<property name="useRegisteredSuffixPatternMatch" value="true" />
		<property name="contentNegotiationManager" ref="contentNegotiationManager"></property>
	</bean>

	<bean
		class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
		<property name="order" value="1" />
		<property name="contentNegotiationManager" ref="contentNegotiationManager" />

		<property name="defaultViews">
			<list>
				<bean
					class="org.springframework.web.servlet.view.json.MappingJackson2JsonView" />
			</list>
		</property>
	</bean>

	<bean id="contentNegotiationManager"
		class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
		<property name="favorParameter" value="false" />
		<property name="parameterName" value="mediaType" />

		<property name="mediaTypes">
			<map>
				<entry key="json" value="application/json" />
				<entry key="xml" value="application/xml" />
			</map>
		</property>
	</bean>
@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Jan 17, 2014

Brian Clozel commented

Hi Michael Osipov and Baptiste Meurant!
Issue is fixed. See this commit.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Jan 17, 2014

Michael Osipov commented

~bclozel, exactly what I wanted to see. Thanks. Will upgrade 4.0 as soon as time allows.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Jan 20, 2014

Baptiste Meurant commented

Thanks a lot. I will test soon.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Jan 21, 2014

Brian Clozel commented

Hi Michael Osipov and Baptiste Meurant

Slight change of plan - I've discussed this issue with other team members and it looks like the current <mvc:annotation-driven/> namespace is already quite rich and other configuration keys were also needed.

So we decided to move those into a <mvc:path-matching /> sub-element with additional configuration keys.

This change shouldn't affect you - in fact, it makes configuration easier to read and add more features (the ability to set your own path-helper and path-matcher).

Check out the new complete example that we test against.

Thanks for your feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment