基于Java的配置和扫描

前端之家收集整理的这篇文章主要介绍了基于Java的配置和扫描前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

在我的xml配置文件中,我可以写

现在我继续进行基于java的配置.如何在没有ApplicationContext的情况下在基于@Configuration的类中执行此操作?

最佳答案
您可以在配置类中使用@ComponentScan批注.

示例:

  1. @Configuration
  2. @ComponentScan("com.acme.app.services")
  3. public class AppConfig {
  4. @Bean
  5. public MyBean myBean() {
  6. // instantiate,configure and return bean ...
  7. }
  8. }

猜你在找的Spring相关文章