- 创建一个application的类来作为入口:此处注意注解@ComponentScan的作用
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication //把类托管到spring当中,请srping帮忙组织一下
@ComponentScan("com.gracie.server") // 需要扫描那些组件, 注意路径的问题
public class Application {
//入口类,用来运行application这个类,基本上属于固定写法
public static void main(String[] args){
SpringApplication.run(Application.class, args);
}
}
- 创建方一个路径,把此路径告知@ComponentScan,让它可以去扫描
- 创建方法: MyGetMethod:
package com.gracie.server;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod