【发布时间】:2018-11-02 18:11:16
【问题描述】:
嗨,我在包 com 中有我的主类 spring boot 应用程序 以及在 com.bbh.fx.pack1 中定义的另外两个 bean。
据我了解,SpringBootApplication 将自动扫描其 pakacge 和 childern 包中的所有组件。但它不是扫描。不知道我错过了什么
**package com.bbh.fx.pack1;**
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
@Component
public class BeanA {
@PostConstruct
public void init() {
System.out.println("in BEANA");
}
}
**package com;**
@SpringBootApplication
public class MainApp{
public static void main(String[] args) {
SpringApplication.run(MainApp.class, args);
}
}
【问题讨论】:
-
SpringApplication.run(MainApp.class, args) in main 方法
-
假设您在 MainApp 中没有 main 方法(请参阅 @Georgy Gobozov 他的评论)...我想知道您是如何测试或启动您的应用程序的吗?
标签: spring spring-boot