2013-02-13 70 views
1

我使用GWT与春天。我遇到了在RemoteServiceServlet中使用@Autowired bean的问题。出于某种原因,这不会自动工作,我需要使用@Configurable才能正常工作。我跟着this approach,但我仍然得到了NullPointerException@Autowired豆:RemoteServiceServlet与春天autowired给nullpointerexception

@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 { 
    ... 
} 

中正在发生的事情的任何指导?我需要提供哪些额外信息?

+0

你在哪里/你如何在春季宣布你的ABean? XML或注释? – spiritwalker 2013-02-13 12:29:33

+0

注释,已编辑原文 – Vjeetje 2013-02-13 12:33:56

+0

您是否在应用程序上下文文件中具有以使ABean成为注入的候选人。 – spiritwalker 2013-02-13 12:38:03

回答

0
+1

请请注意,您应该在此处发布答案的有用观点,或将您的帖子风险删除为[“未答复”](http://meta.stackexchange.com/q/8259)。如果您愿意,您可能仍然包含链接,但仅作为“参考”。答案应该独立,不需要链接。 – 2013-02-16 10:16:21

0

你找到一个可行的解决方案,但仅仅是为了记录,我们有工作如下:

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

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

SomeService是com完整的香草XML定义的bean。也许这或...implements ServletContextAware有所作为。

干杯,