1 回答

TA貢獻(xiàn)1793條經(jīng)驗(yàn) 獲得超6個(gè)贊
因?yàn)槟闹黝怱erverApplication位于另一個(gè)包中,該包是 Spring Boot 應(yīng)用程序的基礎(chǔ)包。
但是控制器Greetings在不同的包中,而不是主類的子包,默認(rèn)情況下,spring boot 應(yīng)用程序?qū)⑺惺褂萌魏卧妥⑨尩念悘膕ub packages基包的任何構(gòu)造型注釋作為springbean 加載到ApplicationContext
@ComponentScan在Main課堂上使用
@SpringBootApplication
@EnableAutoConfiguration
@EnableAsync
@ComponentScan({"com.vmware.skyscraper", "com.skyscraper.vdisizer"})
public class ServerApplication {
private static Logger logger = LoggerFactory.getLogger(ServerApplication.class);
/**
* Start the Spring Boot application.
*
* @param args command line arguments
*/
public static void main(String[] args) {
ApplicationContext context = SpringApplication.run(ServerApplication.class, args);
logger.info("Sample Application started with context {}", context.getDisplayName());
}
}
添加回答
舉報(bào)