1.Annotation
Spring MVC annotations (not specific to Spring Boot)
-
@RestController
handling incoming web requests
-
@RequestMapping
provides “routing” information
- configure
-
@EnableAutoConfiguration.
want to configure Spring
- The “main” Method run goal
public static void main(String[] args) {
SpringApplication.run(Test.class, args);
}
- Running the Example
- Creating an Executable Jar
mvn package
- To run that application, use the java -jar command, as follows:
$ java -jar target/myproject-0.0.1-SNAPSHOT.jar
- If you want to peek inside, you can use jar tvf, as follows:
$ jar tvf target/myproject-0.0.1-SNAPSHOT.jar
mvn
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>SpringBootLearn</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
</parent>
<!-- Additional lines to be added here... -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
code
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@EnableAutoConfiguration
public class Test {
public static void main(String[] args) {
SpringApplication.run(Test.class, args);
}
@RequestMapping("/")
String home() {
return "Hello World!";
}
}