2012-08-15 97 views
0

我得到这个错误与GWT(使用requestfactory)和弹簧NoSuchBeanDefinitionException弹簧和GWT(requestFactory)

org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [org.calibra.server.service.AccountService] is defined: expected single bean but found 0: 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:271) 
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1101) 
at org.calibra.server.SpringServiceLocator.getInstance(SpringServiceLocator.java:24) 
at com.google.web.bindery.requestfactory.server.LocatorServiceLayer.createServiceInstance(LocatorServiceLayer.java:56) 

我的服务定位器

public class SpringServiceLocator implements ServiceLocator { 
    @Override 
    public Object getInstance(Class<?> clazz) { 
     ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(    
      RequestFactoryServlet.getThreadLocalServletContext()); 
     return context.getBean(clazz); 
    } 
} 

我的春节服务

@Service 
public class AccountServiceImpl implements AccountService{ 
    @Override 
    public void addNewAccount(Account account) { 
     ... 
    } 

    @Override 
    public List<Account> loadAllAccounts() { 
     ... 
    } 

} 

Gwt requestContext,参考我的春季服务

@Service(value=AccountService.class, locator=SpringServiceLocator.class) 
public interface AccountRequest extends RequestContext { 

    Request<Void> addNewAccount(AccountProxy account); 

    Request<List<AccountProxy>> loadAllAccounts(); 

} 

我的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> 

我不明白我怎么可以有0的AccountService豆?

我试图在调度员的servlet添加

<bean id="accountService" class="org.calibra.server.service.AccountServiceImpl"/> 

我得到了相同的结果

任何想法?

编辑:如果有人有一个完整的例子,这可能是有用的。

+0

您是否在web.xml中声明了您的RequestFactory servlet? – jrochette 2012-08-15 18:36:41

+0

我有
gwtRequest的com.google.web.bindery.requestfactory.server.RequestFactoryServlet 2012-08-15 18:40:31

+0

我不知道,但我认为你没有servlet映射。请看这里:http://crazygui.wordpress.com/2011/09/23/spring-gwt-integration-using-the-requestfactory-api/更多详情 – jrochette 2012-08-15 18:44:12

回答

0

我认为单独使用ContextLoaderListener是不够的,因为您似乎没有使用DispatcherServlet(是吗?)。 以下线为我工作:

<filter> 
    <filter-name>springRequestContextFilter</filter-name> 
    <filter-class>org.springframework.web.filter.RequestContextFilter</filter-class> 
</filter> 

<filter-mapping> 
    <filter-name>springRequestContextFilter</filter-name> 
    <url-pattern>/gwtRequest</url-pattern> 
</filter-mapping> 
+0

不,我没有DispatcherServlet,所以我的调度程序servlet肯定没有加载。我将需要将这个文件的内容移动到applicationContext.xml中,看看是否能工作......在我尝试你的解决方案之后 – 2012-08-16 13:17:12

+0

我试图将配置注释放在applicationContext.xml中,但没有成功。我也试过你的解决方案没有成功。 – 2012-08-16 17:49:40

+0

你可以发布你的web.xml,applicationContext.xml和dispatcherServlet.xml – 2012-08-16 20:58:03

0

我见过一对夫妇的其他地方这个问题。你应该尝试在你的applicationContext.xml(不是dispatch-servlet.xml)中首先定义AccountServiceImpl作为一个bean,然后看看你是否仍然得到这个错误,如果你不知道它是你错过了这个组件-scan在您的应用程序上下文xml中,这是我认为的情况。

希望这有助于

+0

我认为服务扩展组件......只是更专业 – redfox26 2012-09-13 11:49:56

+0

你是对的,我也只记得...我认为问题是用户没有把组件扫描到他们的应用程序上下文中xml – nightsRey 2012-09-13 21:55:02