2012-08-15 54 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