Can't discover endpoints url

can synonym
can verb
can.'' acronym
meaning of can in hindi
can band
can pronunciation
cant
can y

So today i started using spring-boot, and my point is to create a rest api with spring-boot.

I created just a small project with a rest controller and a simple model. And i'm trying to call the method from the rest controller (with no success)

Controller:

@RestController

    public class RestController {

            @RequestMapping(method = RequestMethod.GET, 
                            produces = MediaType.APPLICATION_JSON_VALUE,
                            value = "/something")
            public @ResponseBody Something getSomething(){
                Something s = new Something ();
                return s;
            }
    }

Main:

@SpringBootApplication
public class SpringBootRestExampleApplication 

    public static void main(String[] args) {
        SpringApplication.run(SpringBootRestExampleApplication.class, args);
    }
}

And an application properties:

server.port=8081
spring.data.rest.basePath=/micro

So if i have a basePath/port and a mapping.. normally i only need to use localhost:8081/micro/something . But for only reason when i use an API Client i got 404 not found for the endpoint /something. Anyone can point me if something is missing? (miss some declaration/..)?

I read other post from stack i tried to use (for example) RequestMappingHandlerMapping

Note: project running with tomcat 8. i already tried localhost:8081/something ; localhost:8081/micro, etc ; added some urlmapping annotation on the rest controller

According to the documentation:

spring.data.rest.base-path= # Base path to be used by Spring Data REST to expose repository resources.

Try to use base-path instead of basePath.

spring.data.rest.base-path=/micro

Or try to set dispatcherServlet path like:

server.contextPath=/micro

For SpringBoot 2.0+:

server.servlet.context-path=/micro

Search logs for:

o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [$URL]
s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/root/test],methods=[GET]}" onto public java.lang.String com.test.Rest.getSomething()

Can dictionary definition, be used to ask for permission in a more polite way. Can definition, to be able to; have the ability, power, or skill to: She can solve the problem easily, I'm sure. See more.

spring.data.rest.base-path will not work because it is specifically made for spring data-rest. You can check this ticket

https://github.com/spring-projects/spring-boot/issues/7816

As a workaround you can use what @oleg.cherednik has suggested or upgrade to spring boot 2.0 and use this

server.servlet.context-path=/micro

CAN (noun) definition and synonyms, can meaning: 1. to be able to: 2. used to say that you can and will do something: 3. to be allowed to: . Learn more. Define can. can synonyms, can pronunciation, can translation, English dictionary definition of can. to be able to, have the power or skill to: I can take a bus to the airport. She can paint very well.

I would reccomend not to use server.contextPath or spring.data.rest.base-path. I faced with different beheviour of this.

Do declare a class with all paths of you API:

public static final class RequestPath {
    public static final String BASE = "/micro";

    public static final String SOMETHING = BASE + "/something";
}

And use it in your controllers:

@RestController
public class RestController {
    @RequestMapping(value = RequestPath.SOMETHING)
    @ResponseBody
    public Something getSomething() {}
}

Finally what you get:

  1. All paths in one file. This could help see it at the same time
  2. Documentation (in case you do not use Swagger or Raml)
  3. You do not care about base path settings, that could works differently (+ you definetly know correct request path to required endpoint).

What does CAN mean? - CAN Definition, See also: Appendix:Variations of "can". Contents. 1 English. 1.1 Etymology 1. 1.1.​1 Alternative forms; 1.1.2 Pronunciation; 1.1.3 Verb. 1.1.3.1 Usage notes  can definition: 1. to be able to: 2. used to say that you can and will do something: 3. to be allowed to: . (Definition of can from the Cambridge Business English

Verb Can, Can may refer to: Contents. 1 Containers; 2 Music; 3 Other; 4 See also. Containers[edit]. Aluminum can · Drink can · Oil can · Steel and tin cans · Trash can  110 synonyms of can from the Merriam-Webster Thesaurus, plus 97 related words, definitions, and antonyms. Find another word for can.

Can, The definition of a can is a container normally made of metal with a lid. An example of can is what tuna comes in. verb. Can means someone or something knows  Can (stylised as CAN) was a German experimental rock band formed in Cologne in 1968 by the core quartet of Holger Czukay (bass, tape editing), Irmin Schmidt (keyboards), Michael Karoli (guitar), and Jaki Liebezeit (drums).

CAN, Could is used as the past tense of can when it means that someone had the ability to do something, or that something was possible: New York was a place  A Controller Area Network (CAN bus) is a robust vehicle bus standard designed to allow microcontrollers and devices to communicate with each other's applications without a host computer. It is a message-based protocol, designed originally for multiplex electrical wiring within automobiles to save on copper, but can also be used in many other

Comments
  • I tried both but still not working .. you tried <localhost>:<port>/micro/something (or something similiar, right?
  • @Tazz search for o.s.b.w.servlet.ServletRegistrationBean in logs, what is URL?