0

在一个 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;
    ...
}

弹簧服务定位器

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

0 回答 0