I have a Spring 3.1/Restlet 2.0 web application. I see that the beans for my resources are instantiated twice per request. I suspect that this is because an instance is created for both the root and servlet contexts, but I can't figure out how to either merge the contexts or only instantiate the beans only in the servlet's context.
Any help would be appreciated. I have included what I believe are the relevant snippets below.
My web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="restlet-basecamp" version="2.5"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd">
<display-name>Integration API</display-name>
<servlet>
<servlet-name>integrationApi</servlet-name>
<servlet-class>org.restlet.ext.spring.RestletFrameworkServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>integrationApi</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
integrationApi-servlet.xml contains the following:
<!-- Scan the package for classes to inject -->
<context:component-scan base-package="com.company.api" />
<!-- Setup the main component -->
<bean id="integrationApiComponent" class="org.restlet.ext.spring.SpringComponent">
<property name="defaultTarget" ref="integrationApiAppliction" />
</bean>
<!-- Setup the router -->
<bean id="integrationApiAppliction" name="root"
class="com.company.api.application.IntegrationApiApplication">
<property name="root" ref="router" />
</bean>
<!-- Define the router -->
<bean name="router" class="org.restlet.ext.spring.SpringBeanRouter" />
<!-- Routes and resources -->
<bean name="/v1/foo/{val}"
class="com.company.api.resource.FooResource"
scope="prototype" autowire="byName" />
<bean name="/v1/status"
class="com.company.api.resource.StatusResource"
scope="prototype" autowire="byName" />
<!-- Load the properties -->
....
<!-- Camel Endpoints -->
....
<!-- Configure the ActiveMQ component -->
....
<!-- Services -->