2.创建启动类

最后更新:2023-09-29 10:01:28 | 状态:未完成

创建启动类,这里只需要注意一下启动时扫描一个org.anyline包,用来注入几个实例,最常用的是AnylineService


package org.anyline.simple.clear;


import org.anyline.service.AnylineService; 
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan; 

@SpringBootApplication
@ComponentScan(basePackages = {"org.anyline"}) //新版本中这一行就不需要了
public class ClearApplication {
    public static void main(String[] args) throws Exception {
        SpringApplication application = new SpringApplication(ClearApplication.class);
        ConfigurableApplicationContext context = application.run(args);
		//可以测试一下serivce有没有成功注入
        AnylineService service = context.getBean(AnylineService.class);
    }
}


首页 最近更新 搜索 提交