How to catch all exceptions in Spring Boot
In this quick tutorial, let’s learn how to catch all exception(s) in Spring Boot. And most probably you want to return customized exception when …
Let’s learn how to create robots.txt file for your spring boot or spring mvc project. Having robots.txt file tells search engine crawlers, such as google, which URLs the crawler can access on your website.
Without diving into further, let’s assume that you have spring boot project. You can create RobotsTxtController
class to return robots.txt file:
@Controller
public class RobotsTxtController {
@GetMapping(value = "/robots.txt", produces = MediaType.TEXT_PLAIN_VALUE)
@ResponseBody
public String getRobotsTxt() {
return "User-agent: *\n" +
"Allow: /\n";
}
}
@ResponseBody
, we are binding method return value to the web response body. In other words, we are just saying, don’t return view from this endpoint.String TEXT_PLAIN_VALUE = "text/plain";
, we are saying that we will return text file.After you run the application in the port 8080, send request to this endpoint: http://localhost:8080/robots.txt
In this quick tutorial, let’s learn how to catch all exception(s) in Spring Boot. And most probably you want to return customized exception when …
Let’s implement oauth2 practical implementation with Spring Boot using PostgreSQL and Thymeleaf. In this application: We will use PostgreSQL to …