Spring: accessing the correct WebApplicationContext with multiple dispatchers declared

I have two Spring contexts declared in my application: one for Spring-MVC queries, and the other for messagebroker Flex / BlazeDS queries mapped to different url patterns:

<servlet-mapping>
    <servlet-name>spring-mvc</servlet-name>
    <url-pattern>/app/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>flex</servlet-name>
    <url-pattern>/messagebroker/*</url-pattern>
</servlet-mapping>

The general context configuration ( /WEB-INF/applicationContext.xml) is declared here , and then each of the two contexts has its own configurations declared in spring-mvc-servlet.xmland, flex-servlet.xmlrespectively.

Inside flex-servlet.xmldeclared beans that are context specific flex. However, when a call arrives http://localhost/messagebroker/*, I get errors that these beans are not available.

This code is inside the custom Spring component, so it directly refers WebApplicationContextto accessing the declared beans:

public ISerializer getSerializer(Object source,boolean useAggressiveSerialization)
{
    ServletContext ctx = FlexContext.getServletContext();
    WebApplicationContext springContext = WebApplicationContextUtils.getRequiredWebApplicationContext(ctx);
    String serializerBeanName = springContext.getBeanNamesForType(ISerializer.class);
}

, . .

, , springContext , configLocation - /WEB-INF/applicationContext.xml

, - ISerializer, , flex-servlet.xml.

? ( )?

EDIT: , , ManageableComponentFactoryBean, , , bean factory. , ApplicationContextAware . :

<bean id="dpHibernateRemotingAdapterComponentFactory"
    class="org.springframework.flex.core.ManageableComponentFactoryBean">
    <constructor-arg
        value="org.dphibernate.adapters.RemotingAdapter" />
    <property name="properties">
        <value>
            {"dpHibernate" :
                {
                    "serializerFactory" : "org.dphibernate.serialization.SpringContextSerializerFactory"
                }
            }
        </value>
    </property>
</bean>

org.dphibernate.serialization.SpringContextSerializerFactory. SpringContextSerializerFactory ApplicationContextAware .

+3
3

flex DispatcherServlet, - , , DispatcherServlet, RequestContextUtils.getWebApplicationContext(request).

RequestContextUtils.getWebApplicationContext(request, ctx), , DispatcherServlet .

+3

Spring :

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public MyCustomBean  implements ApplicationContextAware {

  private ApplicationContext springContext;

  public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    springContext = applicationContext;
  }

  public ISerializer getSerializer(Object source,boolean useAggressiveSerialization)
{
    String serializerBeanName = springContext.getBeanNamesForType(ISerializer.class);
  }
}

bean Spring setApplicationContext bean, , . , .

+1

Hrmmmm ..... I have an almost accurate declaration in my Spring / Flex application using Spring / Flex integration and there is only one application context. Could this be a problem? Do you have beans declared in a Flex context file that is not in the MVC context file, and they really don't load?

0
source

Source: https://habr.com/ru/post/1768411/


All Articles