1

在我的 web 应用程序中,我使用 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) {

        .....
    }
}

网页.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 回答