1、新建一个maven项目,结构如下
在这里插入图片描述
2、添加pom依赖

<?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.yy</groupId>
    <artifactId>demo-spring-boot-starter</artifactId>
    <version>1.0-SNAPSHOT</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.0.RELEASE</version>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
</project>

3、新建测试controller

package com.yy.demo.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by yanyong on 2020/7/17.
 */
@RestController
public class HelloController {
    @RequestMapping(value = "/test", method = RequestMethod.GET)
    public String test(){
        return "hellow world";
    }
}

4、新建configuration

package com.yy.demo;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * Created by yanyong on 2020/7/17.
 */
@Configuration
@ComponentScan(basePackages = {"com.yy.demo"})
public class AutoConfiguration {
}

5、添加spring.factories

org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
  com.yy.demo.AutoConfiguration

6、生成jar包,然后引入到项目中,通过接口访问


版权声明:本文为yy1209357299原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/yy1209357299/article/details/107412922