Spring Boot 默认扫描的包路径是以下几种:
- 启动类所在的包及其子包。
- 应用程序类路径下的所有 jar 包中的类。
- 如果你在启动类上使用 @ComponentScan 注解,则其 value 属性指定的包及其子包也会被扫描。
你可以通过配置文件和代码来修改默认的扫描路径。比如,你可以通过在 application.properties 或 application.yml 中配置 spring.component-scan.base-package 属性来修改默认的扫描路径。
@SpringBootApplication
@EnableTransactionManagement(proxyTargetClass = true)
@MapperScan(basePackages = {"com.frame.springboot.dao", "com.frame.springboot.base"})
public class SpringbootApplication {
public static void main(String[] args) {
SpringApplication app = new SpringApplication(SpringbootApplication.class);
app.addListeners(new MyApplicationStartedEventListener());
app.run(args);
}
static class MyApplicationStartedEventListener implements ApplicationListener<ApplicationStartedEvent> {
private Logger logger = LoggerFactory.getLogger(MyApplicationStartedEventListener.class);
@Override
public void onApplicationEvent(ApplicationStartedEvent event) {
SpringApplication app = event.getSpringApplication();
app.setBannerMode(Banner.Mode.OFF);// 不显示banner信息
logger.info("==MyApplicationStartedEventListener==");
}
}
}