Skip to content

Ability to provide an external base path for controllers [SPR-16336] #20883

@spring-projects-issues

Description

@spring-projects-issues

Caleb Cushing opened SPR-16336 and commented

I'm certain wrote, or commented on a similar bug that I currently can't find. I'd like the ability to do this with classes annotated with @Controller, and perhaps separately for @RestController.

@Configuration
class RestConfig extends RepositoryRestConfigurerAdapter {

    public void configureRepositoryRestConfiguration( RepositoryRestConfiguration config ) {
        config.setBasePath( Routes.PRIVATE );
    }
}

in this way one could write a generic controller with a known subpath, such as /register, but then attach it in the final application as, in my case, /v0/public/register. Suggestions for more flexibility might be a way to setBasePath, explicitly based on annotation.

so you could write config.setBasePath( PublicController.class, "/v0/public" ) where @PublicController is an extension of @Controller, or maybe it'd just be a good idea to allow it for the specific class instead

one of the reasons I have this problem is I'm modularizing all of my components, but now I have to ensure that these paths are configured properly for hateoas before writing a controller, because the controllers path is static, thus changes to hateoas roots for links have to be made before the controller for tests. If I could change the base path of the controller later then I could bundle the controllers under a configuration, and they'd be more reusable modules between apps, and completely configurable.


Affects: 5.0.2

Issue Links:

Referenced from: commits 58cce61, 928b780, 86c8615, d196cdc, 19dc981, 31159a8, e6fef95

2 votes, 7 watchers

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions