views:

232

answers:

1

I wanted to wire the Google App Engine user service in Spring by first creating a UserServiceFactory bean and then using that to get an instance of UserService.

<bean id="googleUserServiceFactory"
      class="com.google.appengine.api.users.UserServiceFactory"></bean>

<bean id="googleUserService" 
      class="com.google.appengine.api.users.UserService" 
      factory-bean="googleUserServiceFactory" 
      factory-method="getUserService"></bean>

I am quite sure this is the right way to wire a bean which you get from a factory but I get this error:

Error creating bean with name 'googleUserService' defined in ServletContext resource [/WEB-INF/hardwire-service.xml]: No matching factory method found: factory bean 'googleUserServiceFactory'; factory method 'getUserService'

It says that the factory method cannot be found. Can it be that the factory method name has changed?

+1  A: 

I got this to work by using a MethodInvokingFactoryBean instead. It still bugs me to think what's wrong with what I did earlier. Anyway:

<bean id="googleUserService"
      class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">

       <property name="staticMethod"
                 value="com.google.appengine.api.users.
                            UserServiceFactory.getUserService">
       </property>
</bean>
Jeune