2015-05-14 38 views
3

我想配置安全(春季安全)申請我的(Maven的)Spring MVC的內彈簧的社會,但是當我試圖訪問/connect//connect/providerid,我總是得到error 404春社會/連接返回404

這裏我的GlassFish服務器日誌,當我嘗試訪問:

Info: Mapped "{[/connect/{providerId}],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.connect(java.lang.String,org.springframework.web.context.request.NativeWebRequest) 
Info: Mapped "{[/connect/{providerId}],methods=[DELETE],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.removeConnections(java.lang.String,org.springframework.web.context.request.NativeWebRequest) 
Info: Mapped "{[/connect/{providerId}],methods=[GET],params=[error],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.oauth2ErrorCallback(java.lang.String,java.lang.String,java.lang.String,java.lang.String,org.springframework.web.context.request.NativeWebRequest) 
Info: Mapped "{[/connect/{providerId}/{providerUserId}],methods=[DELETE],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.removeConnection(java.lang.String,java.lang.String,org.springframework.web.context.request.NativeWebRequest) 
Info: Mapped "{[/connect],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String org.springframework.social.connect.web.ConnectController.connectionStatus(org.springframework.web.context.request.NativeWebRequest,org.springframework.ui.Model) 
Info: Mapped "{[/connect/{providerId}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String org.springframework.social.connect.web.ConnectController.connectionStatus(java.lang.String,org.springframework.web.context.request.NativeWebRequest,org.springframework.ui.Model) 
Info: Mapped "{[/connect/{providerId}],methods=[GET],params=[oauth_token],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.oauth1Callback(java.lang.String,org.springframework.web.context.request.NativeWebRequest) 
Info: Mapped "{[/connect/{providerId}],methods=[GET],params=[code],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.oauth2Callback(java.lang.String,org.springframework.web.context.request.NativeWebRequest) 
Info: Mapped URL path [/resources/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 
Info: Looking for @ControllerAdvice: Root WebApplicationContext: startup date [Thu May 14 16:06:15 PDT 2015]; root of context hierarchy 
Info: Using DataSource [[email protected]] of Hibernate SessionFactory for HibernateTransactionManager 
Info: Creating filter chain: [email protected]1, [org.springframework.secu[email protected]5b252c00, org.spring[email protected]22de3dd7, [email protected]10, [email protected], org.[email protected]68a35517, org.springframework.s[email protected]4d85d53d, org.sp[email protected]3d704ff, org.springframework.[email protected]57243fe2, org.springfram[email protected]53e99103, o[email protected]1917c313, org[email protected]7977c9b0, org.springfr[email protected]a742949] 
Info: Root WebApplicationContext: initialization completed in 3718 ms 
Info: WebModule[null] ServletContext.log():Initializing Spring FrameworkServlet 'DispatcherServlet' 
Info: FrameworkServlet 'DispatcherServlet': initialization started 
Info: FrameworkServlet 'DispatcherServlet': initialization completed in 37 ms 
Info: Loading application [social] at [/social] 
Info: social was successfully deployed in 6,291 milliseconds. 
Severe: PWC6117: File "null" not found 

這裏是我的社會配置類:

@Configuration 
@EnableSocial 
public class SocialConfig implements SocialConfigurer { 

    @Autowired 
    DataSource dataSource; 

    @Override 
    public void addConnectionFactories(ConnectionFactoryConfigurer cfConfig, Environment env) { 
     cfConfig.addConnectionFactory(new LinkedInConnectionFactory("consumerKey", "consumerSecret")); 
    } 

    @Override 
    public UsersConnectionRepository getUsersConnectionRepository(ConnectionFactoryLocator connectionFactoryLocator) { 
     return new JdbcUsersConnectionRepository(dataSource, connectionFactoryLocator, Encryptors.noOpText()); 
    } 

    @Override 
    public UserIdSource getUserIdSource() { 
     return new AuthenticationNameUserIdSource(); 
    } 

    @Bean 
    public ConnectController connectController(ConnectionFactoryLocator connectionFactoryLocator, ConnectionRepository connectionRepository) { 
     return new ConnectController(connectionFactoryLocator, connectionRepository); 
    } 
} 

這裏是我的WebAp pliactionInitializer類:

public class WebInitializer implements WebApplicationInitializer { 

@Override 
public void onStartup(ServletContext servletContext) throws ServletException { 
    WebApplicationContext context = getContext(); 
    servletContext.addListener(new ContextLoaderListener(context)); 
    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet", new DispatcherServlet(context)); 
    dispatcher.setLoadOnStartup(1); 
    dispatcher.addMapping("/"); 
} 

private AnnotationConfigWebApplicationContext getContext() { 
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); 
    context.setConfigLocation("com.gfz.social.springmvc.config"); // java package with all configs 
    return context; 
} 

}

我已經檢查過的pom.xml

<!-- Spring Social --> 
<dependency> 
    <groupId>org.springframework.social</groupId> 
    <artifactId>spring-social-core</artifactId> 
     <version>1.1.0.RELEASE</version> 
    </dependency> 

<dependency> 
    <groupId>org.springframework.social</groupId> 
    <artifactId>spring-social-web</artifactId> 
    <version>1.1.0.RELEASE</version> 
</dependency> 

<dependency> 
    <groupId>org.springframework.social</groupId> 
    <artifactId>spring-social-security</artifactId> 
    <version>1.1.0.RELEASE</version> 
</dependency> 

<dependency> 
    <groupId>org.springframework.social</groupId> 
    <artifactId>spring-social-config</artifactId> 
    <version>1.1.0.RELEASE</version> 
</dependency> 

有人能幫助我嗎? (我已經嘗試閱讀參考代碼和展示示例) 感謝

回答

3

只是一個猜測,但是你碰巧在「connect/{providerId} Connect」或「connect/{providerId} Connected」有任何視圖(JSP,Thymeleaf或其他)嗎?你有「連接/狀態」的觀點嗎?如果不是,那麼這就是404的一種可能性。

回答「/ connect」路徑的控制器方法會收集應用程序中所有已知提供程序的連接狀態信息,然後將其發送到名爲「connect/status」的視圖。對於大多數項目(使用JSP的項目),這意味着您需要一個名爲「status.jsp」的名爲「/ connect」(相對於您的視圖的保存位置)的JSP文件。

對於提供者,每個提供者需要2個文件。例如,如果您在處理Facebook,您將請求「/ connect/facebook」,控制器將收集連接信息並將其發送到名爲「connect/facebookConnect」的視圖(如果您沒有連接)或「connect/facebookConnected」(如果你有連接)。這意味着(在JSP情況下),您需要在「/connect/facebookConnect.jsp」和「/connect/facebookConnected.jsp」處使用JSP。請參閱https://github.com/spring-projects/spring-social-samples/tree/master/spring-social-showcase。這個例子使用Thymeleaf而不是JSP,但是它演示了基本的想法。您可以在src/main/resources/views/connect中找到模板。如果這是一個JSP查看的應用程序,您可能會將它們放在src/main/webapp或src/main/webapp下的某個目錄中。

+0

這是我的錯誤,我已經從展櫃複製了意見,但我使用jsp而不是html(showcase)。現在,它的工作,謝謝你 – kozima