2013-02-13 68 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有所作爲。

乾杯,