【问题标题】:RemoteServiceServlet with spring autowired gives nullpointerexception带有spring autowired的RemoteServiceServlet给出了nullpointerexception
【发布时间】:2013-02-13 12:18:45
【问题描述】:

我在 Spring 中使用 GWT。我遇到了在RemoteServiceServlet 中使用@Autowired bean 的问题。出于某种原因,这不会自动工作,我需要使用@Configurable 才能使其正常工作。我关注了this approach,但我仍然得到NullPointerException@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 {
    ...
}

关于发生了什么的任何指导?我需要提供任何额外信息吗?

【问题讨论】:

  • 你在哪里/如何在 Spring 中声明你的 ABean? XML 还是注解?
  • 注解,编辑原帖
  • 您是否在应用程序上下文文件中有 以使 ABean 成为注入的候选对象。
  • 是的,我之前成功使用了几个@autowired。以某种方式导致问题的是带有 GWT 的 RemoteServiceServlet

标签: spring gwt aspectj spring-aop


【解决方案1】:

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

感谢亚历山大让我朝着正确的方向前进

【讨论】:

  • 请注意,您应该在此处或此站点上发布有用的答案点,否则您的帖子可能会被删除为"Not an Answer"。如果您愿意,您仍然可以包含该链接,但仅作为“参考”。答案应该是独立的,不需要链接。
【解决方案2】:

您找到了一个可行的解决方案,但仅供记录,我们的工作方式如下:

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

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

SomeService 是一个完全普通的 XML 定义的 bean。也许那个或...implements ServletContextAware 会有所不同。

干杯,

【讨论】:

    猜你喜欢
    • 2018-07-15
    • 1970-01-01
    • 2018-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多