![]() ![]() ![]() However, if you now type in localhost:8080/goodbye, you should see Goodbye from Spring Boot. At the root you should still see Hello World from Spring Boot because the is / indicating root. Try adding this new code below your first ( "/goodbye" ) Assuming that's working correctly, you can start to get more adventurous.When you go to the browser, enter the following URL localhost:8080. You can run it again with Ctrl+ R (macOS), or Shift+ F10 (Windows/Linux). You might need to stop it first if it's still running from the previous step. Now we need to re-run our Spring application. RestController class HelloWorldController ( "/" ) To do that we need to add a method with a annotation like our helloWorld one here: The next step is to create a method that will tell Spring that if we go the root of our webserver, we would like to see the string Hello World from Spring Boot. Our REST Controller, HelloWorldController, will therefore be available from the application context. ![]() The first thing we need to do is tell Spring that this is a REST Controller, so you need to add a class level annotation of This annotation means this class will be picked up by the component scan, because it's in the same package as our Application class. It's a little unnerving when you first start using Spring but in time you'll get used to it once you have an appreciation of what Spring is doing behind the scenes for you.Ĭreate a new Java class in the same place as your HelloWorldApplication.java class called HelloWorldController.java. That is handled by the annotation in the Application class which also consists of other annotations, including This means that the current package, and sub packages will be scanned for Spring components. ![]() One important thing to note here is that you don't need to tell your Spring Application class about your (new) Spring Controller class. Now we have our functioning Spring project we need to create a Spring Controller to handle the web requests. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |