Reputation: 787
In my webapp I'am use GWT and I want to use GwtUploader. Problem is that i can't @Autowire any services into my class that handle request. Propably becouse it's not spring component but i don`t have any idea how to solve problem.
Here is my config:
Servlet:
@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>
I am using services in many places and they're working fine.
Upvotes: 1
Views: 141
Reputation: 787
I resolved problem adding:
@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);
}
And now I have problem with session. When i try to use services i get:
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.
Upvotes: 1