基于sptingboot的自动配置,自定义一个starter
service中增加web依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
原有的TestService类
新建TestServiceConfiguration类
新增META-INF spring.factories文件,将TestServiceConfiguration添加到里面变成自动配置类
在web项目中添加TestController类,调用service的方法
启动项目,访问
http://localhost:8080/getName
配置成功。