0

I have develop a simple SpringBoot application with a rest end point as below,

@SpringBootApplication @RestController @RequestMapping(value = "/api") public class Example { @RequestMapping(value="/home", method = RequestMethod.GET) HttpEntity<String> home() { System.out.println("-----------myService invoke-----------"); return new ResponseEntity<String>(HttpStatus.OK); } public static void main(String[] args) throws Exception { SpringApplication.run(Example.class, args); } } 

Above works fine and return 200 in when i invoke the rest end point as, http://localhost:8080/api/home

But now i have move the rest end point to a different class as below,

@RestController @RequestMapping(value = "/api") public class MyController { @RequestMapping(value="/home", method = RequestMethod.GET) HttpEntity<String> home() { System.out.println("-----------myService invoke-----------"); return new ResponseEntity<String>(HttpStatus.OK); } } 

And the Example class looks like,

@SpringBootApplication public class Example { public static void main(String[] args) throws Exception { SpringApplication.run(Example.class, args); } } 

Now i invoke the end point i get below error,

{ "timestamp": 1446375811463, "status": 404, "error": "Not Found", "message": "No message available", "path": "/api/home" } 

What am i missing here please?

1
  • Is MyController in the same package or sub-package as Example? Commented Nov 1, 2015 at 11:15

2 Answers 2

1

Please put the classes, MyController and Example in the same package and try again

Sign up to request clarification or add additional context in comments.

Comments

0

Or also you can put the package of your controller in the main Application , something like this:

@SpringBootApplication @EnableAutoConfiguration @ComponentScan(basePackages={"com.controller"}) public class Application 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.