我有一个名为com.example.service
的包,而在我的Spring配置类中,我有注释@ComponentScan({"com.example.service"},{"com.example.controller"})
。Spring @ComponentScan for @Service
当我尝试使用@Autowire
服务时,代码编译失败,出现NoSuchBeanDefinitionException
。我的服务界面注有@Service
。
目前我使用一个相当难看的解决办法,在我的ExampleConfig.java像
@Bean
public MyService myService() {
return new MyServiceImpl();
}
申报的每一个服务豆一般的@ComponentScan
似乎工作,如果我删除控制器封装,都没有找到控制器。我理解错了什么?请让我知道,如果我错过了任何相关信息。
编译时不会发生异常。保持错误类型分开,否则你会在错误的地方寻找解决方案。 – chrylis 2014-11-04 08:58:02
你对此绝对正确。在这一点上,我的描述与我的描述不精确。 – dexBerlin 2014-11-04 09:29:08