2009-09-04 33 views
3

我想在Spring中连接Google App Engine用户服务,方法是首先创建一个UserServiceFactory bean,然后使用它获取UserService的实例。使用Spring连接Google AppEngine的UserServiceFactory

<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> 

我敢肯定这就是连接你从工厂获得一个bean正确的方式,但我得到这个错误:

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'

它说,该工厂方法无法找到。工厂方法名称是否改变了?

回答

2

我通过使用MethodInvokingFactoryBean来代替它。它仍然让我误以为我早些时候做了什么错事。总之:

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

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

你也可以这样做:

@Configuration 
public class AppConfig { 

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