Firstly you need to download STS from below link:
Download STS (Spring Tool Suite) from Here
Then simply download and install on your machine then open it like below:
After that you need to select or create a workspace where your project will be stored.
After this you need to select File menu and create a Spring Starter project like below:
After this give some information about your project like project name, artifact-id, group-by, type, packaging, java version etc. like below:
After giving all details you have to select dependency Spring-Web like below:
When you click on Finish make sure you have to connect with a stable internet connection because maven download dependency from remote repository to local repository.
Now your project is configured so it will create a default project structure and code like below:
Now you need to open FirstExampleApplication.java file and look like below code:
package com.deepsingh44.demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class FirstExampleApplication { public static void main(String[] args) { SpringApplication.run(FirstExampleApplication.class, args); } }
Create a new class inside the same package HelloController.java and write below code:
HelloController.java
package com.deepsingh44.demo; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloController { @GetMapping("/") public String helloWorld() { return "Hello First Program"; } }
After this right click on your project and select Run As-> Spring Boot App like below:
If your application show error that is port 8080 was already in use like below:
So you need to change the port number in application.properties file like below:
server.port=8888
Then run your application again and it will run successfully like below:
Now you have to open any browser and write like below:
Finally you can see your result on your browser Thanks.
No comments:
Post a Comment