1

私の webapp では GWT を使用しており、GwtUploader を使用したいと考えています。問題は、リクエストを処理するクラスにサービスを@Autowireできないことです。おそらくそれはスプリングコンポーネントではないためですが、問題を解決する方法がわかりません。

これが私の設定です:

サーブレット:

@Component("gwtUploadServlet")
public class GwtUploadServlet extends UploadAction {

private static final long serialVersionUID = 1L;

    @Autowired
    SomeService .....;

    public String executeAction(HttpServletRequest request,
        List<FileItem> sessionFiles) {

        .....
    }
}

web.xml:

<servlet>
    <servlet-name>gwtUploadServlet</servlet-name>
    <servlet-class>xxx.gwtUploader.GwtUploadServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>gwtUploadServlet</servlet-name>
    <url-pattern>/bbsapp/fileUpload</url-pattern>
</servlet-mapping>

私は多くの場所でサービスを使用しており、正常に動作しています。

4

1 に答える 1

1

追加する問題を解決しました:

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);

    // a workaround for forcing this servlet to autowire its components
    WebApplicationContext webAppCtx = WebApplicationContextUtils
            .getRequiredWebApplicationContext(getServletContext());
    webAppCtx.getAutowireCapableBeanFactory().autowireBean(this);
}

そして今、私はセッションに問題があります。サービスを使用しようとすると、次のようになります。

Error creating bean with name 'scopedTarget.userSessionService': Scope 'session' 
is not active for the current thread; consider defining a scoped proxy for this 
bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to 
request attributes outside of an actual web request, or processing a request outside 
of the originally receiving thread? If you are actually operating within a web 
request and still receive this message, your code is probably running outside 
of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener 
or RequestContextFilter to expose the current request.
于 2014-03-04T12:56:25.653 に答える