Spring组件扫描多个包
我希望Spring从两个不同的项目执行依赖项注入,并有一个@Configuration注释的主类,如下所示-Spring组件扫描多个包,spring,Spring,我希望Spring从两个不同的项目执行依赖项注入,并有一个@Configuration注释的主类,如下所示- @Configuration @EnableWebMvc @ComponentScan(value = { "com.x.y", "com.a.b" }) public class AppConfig { } com.x.y下的类是包含AppConfig类的包的一部分,但com.a.b下的类是包含AppConfig类的war文件下打包的不同jar的一部分 当我部署war文件时
@Configuration
@EnableWebMvc
@ComponentScan(value = { "com.x.y", "com.a.b" })
public class AppConfig {
}
com.x.y下的类是包含AppConfig类的包的一部分,但com.a.b下的类是包含AppConfig类的war文件下打包的不同jar的一部分
当我部署war文件时,我得到的错误如下-
Unsatisfied dependency expressed through constructor argument with index 0 of
type [com.a.b.c.d.ClassA]: No qualifying bean of type [com.a.b.c.d.ClassA]
found for dependency: expected at least 1 bean which qualifies as autowire
candidate for this dependency. Dependency annotations: {}; nested exception
is org.springframework.beans.factory.NoSuchBeanDefinitionException:
我不确定我使用@ComponentScan的方式有什么问题。寻找Spring专家的意见
谢谢使用这个@ComponentScan(basePackages={'package1','package2'}这没有帮助。我想补充一点,package2是另一个jar文件的一部分。这仍然可以做到。是的……你是否在你的项目中包含了另一个jar?通过maven还是手动?它需要在那里,这样你才能使用它是的,我有一个.war文件,其中包含jar文件-包含package 2。但是它给出了相同的例外情况。你怎么做你正在创建一个bean??