2

I'm using GWT with Spring. I encountered the problem of using an @Autowired bean in a RemoteServiceServlet. For some reason this doesn't work automatically and I need to use @Configurable to get this working. I followed this approach but I still get a NullPointerException for the @Autowired bean:

@Configurable
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public class AServiceImpl extends RemoteServiceServlet implements AService {

    @Autowired
    private IABean aBean;

    @Override
    public void aMethodFromAService(Args arg[]) {
        aBean.aMethodOfABean(); // this gives a NullPointerException
    }
}

@Component
public class ABean implements IABean {
    ...
}

Any guidance in what is going on? Any extra information I need to provide?

Anders R. Bystrup
  • 15,729
  • 10
  • 59
  • 55
Vjeetje
  • 5,314
  • 5
  • 35
  • 57

2 Answers2

0

http://mitosome.blogspot.be/2011/01/injecting-spring-beans-into-gwt.html

Thanks Alexander for putting me in the right direction

Vjeetje
  • 5,314
  • 5
  • 35
  • 57
  • 1
    Please note that you should post the useful points of an answer here, on this site, or your post risks being deleted as ["Not an Answer"](http://meta.stackexchange.com/q/8259). You may still include the link if you wish, but only as a 'reference'. The answer should stand on its own without needing the link. – Andrew Barber Feb 16 '13 at 10:16
0

You found a workable solution, but just for the record and we have it working as follows:

public class MyServiceImpl extends RemoteServiceServlet 
                           implements MyService, ServletContextAware
{
    @Autowired private transient SomeService someService;
    ....
}

and

<context:annotation-config/>
<context:component-scan base-package="..."/>

The SomeService is a completely vanilla XML-defined bean. Perhaps that or ...implements ServletContextAware makes a difference.

Cheers,

Anders R. Bystrup
  • 15,729
  • 10
  • 59
  • 55