Jeune
Jeune

Reputation: 3548

Wiring a UserServiceFactory of Google AppEngine using Spring

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?

Upvotes: 3

Views: 876

Answers (2)

Jan Willies
Jan Willies

Reputation: 13

you can also do this:

@Configuration
public class AppConfig {

    @Bean
    public UserService userService() {
        return UserServiceFactory.getUserService();
    }

Upvotes: 1

Jeune
Jeune

Reputation: 3548

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>

Upvotes: 2

Related Questions