3.1 以下开始测试(hello-spring-boot-starter)已经封装完毕
第一步:创建maven工程myapp并配置pom.xml文件,这里需要导入我们刚才那个maven,注意刚才那个maven不要忘了install
<?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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
<relativePath/>
</parent>
<groupId>cn.itcast</groupId>
<artifactId>myapp</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--导入自定义starter-->
<dependency>
<groupId>cn.itcast</groupId>
<artifactId>hello-spring-boot-starter</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
~~~
第二步:创建application.yml文件
port: 8080
hello:
name: kevin
address: sx
第三步:创建HelloController
```package com.laoyang.controller;
import com.laoyang.service.HelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
- @author:Kevin
- @create: 2022-09-17 09:57
@Description:
*/
@RestController
@RequestMapping("/hello")
public class hellocontroller {@Autowired
private HelloService helloService;@GetMapping("/say")
public String sayHello(){return helloService.sayHello();
}
}
```