Spring / Restlet项目中的资源每个请求实例化两次

时间:2014-02-25 17:52:09

标签: spring restlet spring-3 applicationcontext restlet-2.0

我有一个Spring 3.1 / Restlet 2.0 Web应用程序。我看到每个请求都会为我的资源的bean实例化两次。我怀疑这是因为为root和servlet上下文创建了一个实例,但我无法弄清楚如何合并上下文或仅在servlet的上下文中实例化bean。

任何帮助将不胜感激。我已将我认为相关的片段包括在内。

我的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包含以下内容:

<!-- 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 -->

0 个答案:

没有答案