Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: NoSuchBeanDefinitionException with spring and gwt (requestFactory)

  1. #1
    Join Date
    Apr 2008
    Location
    spain
    Posts
    21

    Default NoSuchBeanDefinitionException with spring and gwt (requestFactory)

    I get this error with a gwt (using requestfactory) and spring

    Code:
        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)
    My service locator

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

    Code:
        @Service
        public class AccountServiceImpl implements AccountService{
             @Override
             public void addNewAccount(Account account) {
               ...
             }
    
             @Override
             public List<Account> loadAllAccounts() {
                ...
             }
    
        }
    Gwt requestContext

    Code:
        @Service(value=AccountService.class, locator=SpringServiceLocator.class)
        public interface AccountRequest extends RequestContext {
        
            Request<Void> addNewAccount(AccountProxy account);
    
            Request<List<AccountProxy>> loadAllAccounts();
       
        }
    My web.xml

    Code:
    <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>
    my dispatcher-servlet.xml
    Code:
    <context:annotation-config />
    <context:component-scan base-package="com.calibra" />
    I don't understand why i have 0 bean

    Any idea?
    Last edited by collinm; Aug 15th, 2012 at 04:08 PM.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    There is nothing that is loading your dispatcher-servlet.xml. Your beans should all be loaded in the applicationContext.xml.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Apr 2008
    Location
    spain
    Posts
    21

    Default

    Quote Originally Posted by Marten Deinum View Post
    There is nothing that is loading your dispatcher-servlet.xml. Your beans should all be loaded in the applicationContext.xml.
    I will need to add dispatcher-servlet.xml to my config, so i will have 2 servlet.

    I saw this file: https://code.google.com/p/gwtcontact...EB-INF/web.xml

    Don't know it's is the good way to do it. Will test it tonight.

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    That won't work either... You can only access beans loaded by the ContextLoaderListener you cannot access beans from servlet x loaded by servlet y. So as mentioned the beans must be loaded with the ContextLoaderListener.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Apr 2008
    Location
    spain
    Posts
    21

    Default

    Quote Originally Posted by Marten Deinum View Post
    That won't work either... You can only access beans loaded by the ContextLoaderListener you cannot access beans from servlet x loaded by servlet y. So as mentioned the beans must be loaded with the ContextLoaderListener.
    ok, my dispatcher-servlet.xml is not loaded, so i need to add the contain of this file to applicationContext.xml ?
    <context:annotation-config />
    <context:component-scan base-package="com.calibra" />
    and maybe will need to add
    <bean id="accountService" class="org.calibra.server.service.AccountServiceIm pl"/>
    Last edited by collinm; Aug 16th, 2012 at 03:29 AM.

  6. #6
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    You only need to component-scan (annotation-config is implied when using componet-scan). Component-scanning would be pretty useless if one would still need to configure the services explicitly.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  7. #7
    Join Date
    Apr 2008
    Location
    spain
    Posts
    21

    Default

    Quote Originally Posted by Marten Deinum View Post
    You only need to component-scan (annotation-config is implied when using componet-scan). Component-scanning would be pretty useless if one would still need to configure the services explicitly.
    ok thank, will try tonigh and give you the result.

  8. #8
    Join Date
    Apr 2008
    Location
    spain
    Posts
    21

    Default

    i put

    <context:component-scan base-package="com.calibra" />
    in applicationContex.xml file, but i got the same error.

  9. #9
    Join Date
    Apr 2008
    Location
    spain
    Posts
    21

    Default

    I posted all the source there: http://filebin.ca/CRE3HbzFunH

  10. #10
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    I'm not that familair with GWT but one thing I noticed is that you are trying to get the AccountServiceImpl whereas you should get the interface (due to proxy creation for instance).

    Also make sure that everything is deployed correctly (you probably want to enable debug logging for spring to see which beans are registered at startup).
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •