简体   繁体   English

不同项目中的应用程序上下文为空并且无法访问bean

[英]Application Context Null in different project and unable to access beans

I have a project (project1) which has beans declared using @component and using application context I am able to access the beans. 我有一个项目(project1),该项目具有使用@component声明并使用应用程序上下文声明的bean,我能够访问bean。 Now there is another project(spring boot project- project2) in which I am using this project1 as dependency. 现在有另一个项目(spring boot project- project2),其中我使用这个project1作为依赖项。 In that I am trying to access beans of project1 using autowired annotation but it is throwing null pointer exception both for beans and Application context. 在这种情况下,我尝试使用自动装配的注释访问project1的bean,但是它为bean和应用程序上下文都抛出了空指针异常。 How can I access application context of project1 which has access to those beans in my project so that I can use both autowired application context and access beans of project1 in project2 Any idea what is wrong and why autowiring not working. 我如何访问project1的应用程序上下文,而该上下文可以访问项目中的那些bean,这样我既可以使用自动装配的应用程序上下文,也可以访问project2中的project1的bean。任何想法都出了什么问题以及为什么自动装配不起作用。

Thanks 谢谢

You need to import configuration from project 1 into project 2. Something like below 您需要将配置从项目1导入到项目2中。

@Configuration
@EnableBatchProcessing
@ComponentScan({"abc.","com.abc"})
@Import({Project1Config.class})
public class Project2Configuration {
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM