Spring - 上下文扫描因requestfactory(gwt)而失败

时间:2012-08-24 14:41:42

标签: spring gwt requestfactory

在gwt web应用程序中我使用spring。

如果我在我的applicationContext.xml文件中使用

<context:component-scan base-package="com.test.**"/> 

找不到我的bean,我需要在applicationContext文件中手动声明它。

我的web.xml文件

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
     <servlet-name>gwtRequest</servlet-name>
     <servlet-class>com.google.web.bindery.requestfactory.server.RequestFactoryServlet</servlet-class>
</servlet>

<servlet-mapping>
     <servlet-name>gwtRequest</servlet-name>
     <url-pattern>/gwtRequest</url-pattern>
</servlet-mapping>

<welcome-file-list>
     <welcome-file>welcomeGWT.html</welcome-file>
</welcome-file-list>

组件扫描失败有什么原因吗?

定位器类

public class AccountLocator extends Locator<Account, Long> {

    @Autowired
    private AccountDAO accountDAO;
    ...
}

Spring服务定位器

public class SpringServiceLocator implements ServiceLocator {

    @Override
    public Object getInstance(Class<?> clazz) {
        HttpServletRequest request = RequestFactoryServlet.getThreadLocalRequest();
        ServletContext servletContext = request.getSession().getServletContext();
        ApplicationContext context =       WebApplicationContextUtils.getWebApplicationContext(servletContext);
    return context.getBean(clazz);
}

}

服务器层

@Service
public class AccountServiceImpl implements AccountService{
    @Autowired
    private AccountDAO accountDAO;
...
}

道层

@Repository
public class AccountDAOImpl implements AccountDAO{
...
}

0 个答案:

没有答案