How to set base url for rest in spring boot

0 votes
I'm trying to mix mvc and rest in a single spring in boot project.

I want to set base path for all rest controllers (eg. example.com/api) in a single place (I don't want annotate each controller with @RequestMapping('api/products'), instead, just @RequestMapping('/products').

Mvc controllers should be accessable by example.com/whatever

Is it possible?
May 22, 2020 in Java by kartik
• 37,520 points
14,380 views

1 answer to this question.

0 votes

Hello @kartik,

Set it up in your application.yml (or analogical config file):

spring:
    data:
        rest:
            basePath: /api

As I can remember that's it - all of your repositories will be exposed beneath this URI.

Hope this works!!

Get your Spring Certification today to become certified.

Thanks!

answered May 22, 2020 by Niroj
• 82,840 points

Related Questions In Java

0 votes
1 answer

How to set a timer in Java?

To work on timer in java, you ...READ MORE

answered May 16, 2018 in Java by Daisy
• 8,140 points
1,217 views
0 votes
1 answer

How to set Encoding in Java ?

Unfortunately, the file.encoding property has to be specified as ...READ MORE

answered May 29, 2018 in Java by Rishabh
• 3,620 points
16,240 views
0 votes
1 answer

How to encode the HTTP URL address in Java?

Use one of the constructors with more ...READ MORE

answered Oct 23, 2018 in Java by Sushmita
• 6,920 points
3,365 views
0 votes
1 answer

Can anyone show how to implement SortByValue in Tree Map for Java ?

You can't have the TreeMap itself sort on the ...READ MORE

answered Dec 10, 2018 in Java by Sushmita
• 6,920 points

edited Dec 10, 2018 by Sushmita 791 views
0 votes
1 answer

How to redirect to an external URL from controller action in Spring MVC?

Hello @kartik, You can do it with two ...READ MORE

answered May 22, 2020 in Java by Niroj
• 82,840 points

edited Mar 4, 2022 by Sarfaraz 26,884 views
0 votes
1 answer

Bean life cycle in Spring Bean Factory Container

Bean life cycle in Spring Bean Factory ...READ MORE

answered Aug 30, 2018 in Java by code.reaper12
• 3,500 points
3,295 views
0 votes
2 answers
0 votes
1 answer

How to configure port for a Spring Boot application?

Hello @kartik, You can set port in java ...READ MORE

answered May 22, 2020 in Java by Niroj
• 82,840 points
2,988 views
0 votes
2 answers

How to log SQL statements in Spring Boot?

HI.. try using this in your properties file: logging.level.org. ...READ MORE

answered Sep 25, 2020 in Java by SRI

edited Sep 25, 2020 by Sirajul 4,932 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP