Announcement Announcement Module
Collapse
No announcement yet.
NoSuchBeanDefinitionException with spring and gwt (requestFactory) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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, 05:08 PM.

  • #2
    There is nothing that is loading your dispatcher-servlet.xml. Your beans should all be loaded in the applicationContext.xml.

    Comment


    • #3
      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.

      Comment


      • #4
        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.

        Comment


        • #5
          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, 04:29 AM.

          Comment


          • #6
            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.

            Comment


            • #7
              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.

              Comment


              • #8
                i put

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

                Comment


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

                  Comment


                  • #10
                    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).

                    Comment


                    • #11
                      Originally posted by Marten Deinum View Post
                      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).

                      you mean in the AccountRequest interface?

                      i already tester with the interface, i will test it again after the work

                      in the gwt documentation: https://developers.google.com/web-to...RequestFactory, it use the class...
                      Last edited by collinm; Aug 17th, 2012, 03:07 AM.

                      Comment

                      Working...
                      X