Why do I get 404 for rest with spring-boot
The first thing I would try is to put @RequestMapping("/")
on the class definition of the controller. Keep the same value on the method.
Another thing, unrelated to your problem, is that you do not need to define that custom query. JPA is actually smart enough to do the query you defined just by using that method name. Check out the findByLastName
example here: https://spring.io/guides/gs/accessing-data-jpa/.
Why do I get 404 Not Found in Spring Boot
Ok, so the issue was very silly, and the solution is super simple:
I was using @Controller adnotation in my RfidReaderController which is from springframework.stereotype library. I changed it to @RestController and now it works.
just as follows:
@Controller
@CrossOrigin
@RequiredArgsConstructor
@RequestMapping("/rfid")
public class RfidReaderController {
...
How to fix 'HTTP-404' error, during GET request in REST web service using spring boot
The issue is resolved, @Component needed to be added to Service class, along with @ComponentScan in the main application class:
package com.in28minutes.springboot.service;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.stereotype.Component;
import com.in28minutes.springboot.model.Course;
import com.in28minutes.springboot.model.Student;
@Component
public class StudentService {
public List<Course> retrieveCourses(String studentId) {
Map<String, Course> courses = Student.getStudentObj(studentId).getCourses();
List<Course> courseList =
courses.values().parallelStream().collect(Collectors.toList());
return courseList;
}
public Course retrieveCourse(String studentId, String courseId) {
return Student.getStudentObj(studentId).getCourses().get(courseId);
}
}
package com.in28minutes.springboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan("com.in28minutes.springboot")
public class StudentServicesApplication {
public static void main(String[] args) {
SpringApplication.run(StudentServicesApplication.class, args);
}
}
Related Topics
How to Find an Object in an Arraylist by Property
Spring Rest - Create Zip File and Send It to the Client
Serialize a Double to 2 Decimal Places Using Jackson
How to Hide a Request Field in Swagger API
Selecting from Div Class Dropdown - Selenium
Include Comma in a Field Value of CSV (Delimeter as Comma) in Java
Get Requestbody and Responsebody At Handlerinterceptor
How to Replace Non-Printable Unicode Characters in Java
Query in Repository With Limit
Connection Java - Mysql:Public Key Retrieval Is Not Allowed
@Responsebody , Responseentity Spring Return Object as Json
How to Store a String Longer Than 4000 Characters in an Oracle Database Using Java/Jdbc
How to Get Http Response Code Using Selenium Webdriver
Java: How to Ask User If He/She Wants to Continue Program
Jpa: Update Only Specific Fields
How to Subtract a Constant Value from All Elements of an Array
Counting Unique Characters in a String
Java:How to Determine the Correct Charset Encoding of a Stream