在Spring MVC项目中,Spring Beans没有使用DWR加载

时间:2014-02-05 01:35:34

标签: java spring spring-mvc dwr

由于我的web.xml文件中的DWR配置,我的Spring MVC应用程序中的延迟加载bean无法正常工作。如果我注释掉DWR配置,则延迟加载有效。我看到在应用程序启动期间构建了Bean ProgressWorker1和ProgressWorker2(我在每个bean的构造函数中都有一个临时println)。这些bean扩展了ProgressWorker抽象类。以下是我的配置和代码。

DWR是否会导致此问题,或者多个Servlet标记是否导致延迟加载bean无效?

web.xml(摘录)

<servlet>
    <servlet-name>tester</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

    <servlet>
      <servlet-name>dwr</servlet-name>
      <servlet-class>org.directwebremoting.spring.DwrSpringServlet</servlet-class>
      <init-param>
        <param-name>debug</param-name>
        <param-value>false</param-value>
      </init-param>
      <init-param>
          <param-name>activeReverseAjaxEnabled</param-name>
          <param-value>true</param-value>
      </init-param>
      <init-param>
          <param-name>maxWaitAfterWrite</param-name>
          <param-value>-1</param-value>
      </init-param>

      <init-param>
        <param-name>org.directwebremoting.extend.ServerLoadMonitor</param-name>
        <param-value>org.directwebremoting.impl.PollingServerLoadMonitor</param-value>
      </init-param>

      <init-param>
          <param-name>disconnectedTime</param-name>
          <param-value>1000</param-value>
      </init-param>
      <load-on-startup>2</load-on-startup>
    </servlet>


    <servlet-mapping>
      <servlet-name>dwr</servlet-name>
      <url-pattern>/dwr/*</url-pattern>
    </servlet-mapping>


<servlet-mapping>
    <servlet-name>tester</servlet-name>
    <url-pattern>*.htm</url-pattern>
</servlet-mapping>

applicationContext.xml(snippet)

<bean id="progresssWorker" abstract="true" class="com.tester.progress.ProgressWorkerAbstract">
    <property name="testSystem" ref="testSystem"/>
    <property name="testService" ref="testSystemService"/>
    <property name="progressDao" ref="progressDao"/>
</bean>

<bean id="progressWorker1" lazy-init="true" class="com.tester.progress.ProgressWorker1" parent="progresssWorker" />
<bean id="progressWorker2" lazy-init="true" class="com.tester.progress.ProgressWorker2" parent="progresssWorker" />

<bean id="progressWorkerFactory" class="com.tester.progress.ProgressWorkerFactoryImpl" />

ProgressWorkerFactoryImpl类

public class ProgressWorkerFactoryImpl implements ProgressWorkerFactory, ApplicationContextAware  {


    private ProgressWorker1 progressWorker1;
    private ProgressWorker2 progressWorker2;
    private static ApplicationContext CTX;


    @Override
    public void setApplicationContext(ApplicationContext ctx) throws BeansException {
        CTX = ctx;
    }


    @Override
    public ProgressWorker getProgressWorker(int type) {
        switch(type) {
            case 1:
                progressWorker1 = (ProgressWorker1) CTX.getBean("progressWorker1");
                return progressWorker1;
            case 2:
                progressWorker2 = (ProgressWorker2) CTX.getBean("progressWorker2");
                return progressWorker2;
            default:
                return null;
        }
    }

}

0 个答案:

没有答案