I am new to Java Spring, so I may have some difficulties explaining my configurations.
I have a Java Spring Web Application that contains a Servlet that needs to access a Bean. However, the issue is the Bean is located in another common project xml file that gets loaded whenever the application get's loaded.
Project C
common-context.xml
<bean id="common-bean" ...>
CommonLoader.class
protected AbstractApplicationContext mContext;
public void start(String[] pArgs) {
mContext = new ClassPathXmlApplicationContext("common-context.xml");
}
In another Project A, I have a servlet that needs to access common-bean, however, it is unable to find the bean.
Project A
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
ApplicationContext mAppContext = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
for (String name : mAppContext.getBeanDefinitionNames()) {
System.out.println(name);
}
}
However, nothing gets found even though I know for a fact that common-bean is running due to the logs. My guess is because they are running in separate ApplicationContexts, they cannot talk to each other even though they are in the same Java application.
Is there any way for them to communicate or pass the bean directly to the servlet?