2014-11-16 51 views
1

我是新來的彈簧,承擔與我:○如何在春季創建Google Oauth?

我使用Spring引導v1.1.8.RELEASE

我試圖讓我的網站工作谷歌的Oauth連接。

所以我試圖讓彈簧社會谷歌,而Twitter的& Facebook的一個正在工作。

我看了這個http://gabiaxel.github.io/spring-social-google-reference/overview.html 我從其他提供商(推特& Facebook)閱讀Spring.io的教程。

因此,這裏是我的代碼:

package app.controllers; 

import javax.inject.Inject; 

import org.springframework.social.google.api.Google; 
import org.springframework.stereotype.Controller; 
import org.springframework.ui.Model; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 

@Controller 
@RequestMapping("/google") 
public class GoogleController { 

    private Google google; 

    @Inject 
    public GoogleController(Google google) { 
     this.google = google; 
    } 

    /** 
    * 
    * @param model 
    * @return 
    */ 
    @RequestMapping(method = RequestMethod.GET) 
    public String helloGoogle(Model model) { 
     if (!google.isAuthorized()) { 
      return "redirect:/connect/google"; 
     } 

     model.addAttribute(google.plusOperations().getGoogleProfile()); 
     return "testGoogle"; 
    } 

} 
  • 我有文件,就像在我的模板 googleConnect.html和googleConnected.html的Facebook。

  • 的Maven正確進口的依賴

  • 的application.properties有祕密的appid從谷歌 應用程序,我創建

以下是錯誤我:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'googleController' defined in file [C:\Users\Antoine\Documents\NetBeansProjects\p0907931-cinemagik\app\target\classes\app\controllers\GoogleController.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.social.google.api.Google]: : No qualifying bean of type [org.springframework.social.google.api.Google] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.social.google.api.Google] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {} 

這個bean應該像自動裝配右邊的其他供應商?

謝謝你的時間。

編輯:

這個bean是工作,但我不知道如何實現它在我的控制?

@Configuration 
public class SocialConfig { 

    @Inject 
    private Environment environment; 

    @Bean 
    public ConnectionFactoryLocator connectionFactoryLocator() { 
     ConnectionFactoryRegistry registry = new ConnectionFactoryRegistry(); 
     registry.addConnectionFactory(new GoogleConnectionFactory(
      environment.getProperty("superAPI"), 
      environment.getProperty("superSecret"))); 

     return registry; 
    } 

} 

回答

0
package app.controllers; 

import javax.inject.Inject; 

import org.springframework.social.google.api.Google; 
import org.springframework.stereotype.Controller; 
import org.springframework.ui.Model; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 

@Controller 
public class GoogleController { 

    private Google google; 

    @Inject 
    public GoogleController(Google google) { 
     this.google = google; 
    } 

    /** 
    * 
    * @param model 
    * @return 
    */ 
    @RequestMapping(method = RequestMethod.GET,value="/google") 
    public String helloGoogle(Model model) { 
     if (!google.isAuthorized()) { 
      return "redirect:/connect/google"; 
     } 

     model.addAttribute(google.plusOperations().getGoogleProfile()); 
     return "testGoogle"; 
    } 

} 
+0

你好,謝謝你的回答,但我得到了同樣的錯誤:2014-11-16 10:48:29.578錯誤428 --- [main] osboot.SpringApplication:應用程序啓動失敗 org.springframework.beans。 factory.UnsatisfiedDependencyException:創建名爲'googleController'的bean時出錯... – hyptos