1、 启动一个hello。
使用maven 进行构建?pom.xml 文件构建如下,构建一个web启动器。
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
</parent>
<dependencyManagement>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencyManagement>
2、打印Hello., MVC 风格
1> 构建启动器类
package com.fandong.weapon;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
@EnableAutoConfiguration
@ComponentScan
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class);
}
}
@EnableAutoConfiguration : 表示使用约定的配置
@ComponentScan: 表示扫描包。
2> 构建helloController
package com.fandong.weapon.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@GetMapping("/hello")
public String hello(){
return "hello";
}
}
启动spring boot 类
3、在浏览器输入: localhost:8080/hello