2009-09-04 36 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(); 
    }