Skip to content
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

Endpoints at Reactive routes require a prefix "/" but @RequestMapping and others works even without it. #23722

Closed
CODINGSAINT opened this issue Sep 27, 2019 · 2 comments
Labels
status: duplicate A duplicate of another issue

Comments

@CODINGSAINT
Copy link

CODINGSAINT commented Sep 27, 2019

Affects: <Spring Framework 5>


If we have use @GetMapping ("hello") or @GetMapping("/hello") both works seamlessly .Example: -

@GetMapping("user/{userId}")
public Optional<User> getUser(@PathVariable("userId") Long id) {
	logger.info(" User id {}", id);
	return userRepository.findById(id);
}

With Reactive Routes it is not same, it accepts only with prefix "/" which is counter intuitive. Example : -

@Bean
    public RouterFunction userRoutes() {
        return RouterFunctions.route(
                RequestPredicates.GET("/users"), userHandler::getAll)
                .andRoute(RequestPredicates.POST("/user"), userHandler::add)
                .andRoute(RequestPredicates.PUT("/user"), userHandler::update)
                .andRoute(RequestPredicates.GET("/user/{id}"), userHandler::get)
                .andRoute(RequestPredicates.DELETE("/user/{id}"), userHandler::delete);
    }

It might not be a bug but certainly can be an enhancement.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Sep 27, 2019
@StevenPG
Copy link

StevenPG commented Oct 13, 2019

Can you reproduce this? Looking through the source, it seems the missing / is accounted for in the 5.2.0 release tag. (https://github.com/spring-projects/spring-framework/blob/v5.2.0.RELEASE/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RequestPredicates.java)

public static RequestPredicate POST(String pattern) {
	return method(HttpMethod.POST).and(path(pattern));
}
// and
public static RequestPredicate path(String pattern) {
	Assert.notNull(pattern, "'pattern' must not be null");
	if (!pattern.isEmpty() && !pattern.startsWith("/")) {
		pattern = "/" + pattern;
	}
	return pathPredicates(DEFAULT_PATTERN_PARSER).apply(pattern);
}

@rstoyanchev
Copy link
Contributor

Resolving as duplicate of #22795.

@rstoyanchev rstoyanchev added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Oct 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

4 participants