RestController in Spring boot- 404 ERROR instead of JSON object [duplicate]

RestController in Spring boot- 404 ERROR instead of JSON object [duplicate]



This question already has an answer here:



I have a very simple Rest Controller only for test and its not working..
I'm using spring boot and postman for client-side.



my rest controller:


@RestController
@RequestMapping("system")
public class LoginController {

public static CouponSystemResponse csRes = new CouponSystemResponse();

@RequestMapping(value = "login", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
public CouponSystemResponse login(@RequestParam(value = "username") String username,
@RequestParam(value = "password") String password, @RequestParam(value = "type") String type) {
csRes.setMessage("You have successfully logged in");
csRes.setStatus("OK");
return csRes;



CouponSystemResponse:


@Component
public class CouponSystemResponse {

private String status = "";
private String message = "";

public CouponSystemResponse()


public CouponSystemResponse(String status, String message)
super();
this.status = status;
this.message = message;


public String getStatus()
return status;


public void setStatus(String status)
this.status = status;


public String getMessage()
return message;


public void setMessage(String message)
this.message = message;


@Override
public String toString()
return "CouponSystemResponse [status=" + status + ", message=" + message + "]";



postman output:



postman output



url: http://localhost:8080/system/login?username=admin&password=1234&type=ADMIN



Can't figure what the problem could be. Appreciate any help.



Update: I add picture of main app+structure:



main app



This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






Shouldnt it be slash login like "/login" instead of just login ? on the request mapping

– Alexandar Petrov
Sep 14 '18 at 22:32






Unrelated: Using a static object as return value is a bad idea. Don't do it!! Create the instance in the method.

– Andreas
Sep 14 '18 at 22:34



static






@AlexandarPetrov well I tried it, same result

– hindi1991
Sep 14 '18 at 22:34






Actualy I just notice you have a second reposnse mapping on class level. Remove it.

– Alexandar Petrov
Sep 14 '18 at 22:35






@Ekrem The @RestController implies @ResponseBody on all methods.

– Andreas
Sep 14 '18 at 22:36


@RestController


@ResponseBody




1 Answer
1



All your components are in subpackages of package com.orel.couponsystem, but your @SpringBootApplication annotated CouponWebApplication class is in package com.orel.t.couponsystem.config, which means that none of your components are auto-scanned.


com.orel.couponsystem


@SpringBootApplication


CouponWebApplication


com.orel.t.couponsystem.config



Standard solution: Move class CouponWebApplication out to the base package:


CouponWebApplication


package com.orel.couponsystem;



Alternate solution: Explicitly name the base package:


@SpringBootApplication(scanBasePackages = "com.orel.couponsystem")

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)