Issue
My Spring boot project is connected to MSSQL Server but while hitting the post response getting 404 status code in postman:
Postman:
{
"timestamp": 1625696983693,
"status": 404,
"error": "Not Found",
"path": "/house"
}
MyController.java
public class MyController {
@Autowired
private HouseService houseService;
// get the values
@GetMapping("/house")
public List<House> getApiHouseValues(){
return this.houseService.getHouseValues();
}
// add values
@PostMapping("/house")
public GateHouse addApiHouseValues(@RequestBody House house) {
return this.houseService.addHouseValues(house);
}
}
application.properties
server.port=9090
spring.datasource.url=jdbc:sqlserver://server-name;databaseName=log
spring.datasource.username=loguser
spring.datasource.password=test
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
# hibernate configuration
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
Also checked in SQL Server but database is empty, don't know where I am going wrong.
Solution
404 mean page not found add below things on controller level.
@RestController
@RequestMapping(value ="/")
public class MyController {
GetMapping("house")
public List<House> getApiHouseValues(){
return this.houseService.getHouseValues();
}
}
Answered By - S. Anushan