Good day. The situation is this - there is a Tomcat, Alfresco ( ECM ) and BIRT (reports) are spinning on it. It is necessary to make it so that from the modules (jar) or pages (jsp) of BIRT you can have access to the “services” of Alfresco (in simple terms: they provide access to different types of ECM repository data). Alfresco uses the Spring Framework . There is a java-class that receives the current servlet (BIRT).

public void initialize(HttpServlet servlet) { servletContext = servlet.getServletContext(); } 

I am trying to access the bean as follows:

 ServletContext alfrescoWebContext = servletContext.getContext("/alfresco"); WebApplicationContext alfrescoSpringContext = WebApplicationContextUtils .getWebApplicationContext(alfrescoWebContext); // serviceRegistry объект типа ServiceRegistry - относится к API Alfresco serviceRegistry = (ServiceRegistry) AlfrescoSpringContext .getBean(ServiceRegistry.SERVICE_REGISTRY); 

When you try to work the same way, the following crashes:

 java.lang.IllegalStateException: Context attribute is not of type WebApplicationContext: Root WebApplicationContext: startup date [Thu Aug 01 10:01:04 MSK 2013]; root of context hierarchy 

The project structure is as follows:

 tomcat |_ webapps |_ alfresco |_ birt 

How to solve this? Maybe there is another way?

============================================

The question was solved by pulling the attributes out of context, thanks @Barmaley for the tip.

    1 answer 1

    Not strong in Spring'e, but from the general provisions it is known that:

    1. It’s just that data exchange between different contexts is generally forbidden; special server-level manipulations are required to allow this.
    2. Even if data exchange is allowed, all the same, each context has its own session manager, so ideally it is also necessary to transfer between session contexts (if you need to receive data getAttribute() with sessions - that is, getAttribute() ).

    With regard to Tomcat, if my memory does not change in the settings of server.xml, I need to register something like:

     <Host> <Context path="/alfresco" crossContext="true" /> <Context path="/birt" crossContext="true" /> </Host> 

    Then cross-context data exchange will be available.

    • crossContext = "true" - already set, and did not solve the problem = \ And the general picture of the "receiving" is correct? Those. need to dig with the server? - Dima346753
    • Well, everything seems to be correct, the only thing is that when you try to get the context of Spring, while in Birt, it fails, which is probably due to the fact that Birt knows nothing about Spring, so try to get non-spring attributes or in Alfresco add special attributes for Birt to the context - Barmaley