Spring 社交/连接 return 404

Spring social /connect return 404

我正在尝试在我的 (maven)spring MVC 安全(spring 安全)应用程序中配置 spring 社交,但是当我尝试访问 /connect//connect/providerid ,我总是得到 error 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 [org.apache.commons.dbcp2.BasicDataSource@65a12534] of Hibernate SessionFactory for HibernateTransactionManager
Info:   Creating filter chain: org.springframework.security.web.util.matcher.AnyRequestMatcher@1, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@5b252c00, org.springframework.security.web.context.SecurityContextPersistenceFilter@22de3dd7, org.springframework.security.web.header.HeaderWriterFilter@17b3d10, org.springframework.security.web.csrf.CsrfFilter@2bffe1ad, org.springframework.security.web.authentication.logout.LogoutFilter@68a35517, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@4d85d53d, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@3d704ff, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@57243fe2, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@53e99103, org.springframework.security.web.session.SessionManagementFilter@1917c313, org.springframework.security.web.access.ExceptionTranslationFilter@7977c9b0, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@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

这是我的社交配置 class:

@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);
    }
}

这是我的 WebAppliactionInitializer class:

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>

有人可以帮助我吗? (我已经尝试阅读参考代码和展示示例) 谢谢

错误 PWC6117: File "null" not found 在 spring 无法正确映射模型和视图时发生。

在你的控制器中 class 你需要像

这样的配置

return new ModelAndView("WEB_INF/whereverSpringCanFindYourJSP");

  • Cryptic jetty-maven-plugin error message 'ERROR: PWC6117: File "null" not found'

希望对您有所帮助!

祝你好运!

只是猜测,但您碰巧在 "connect/{providerId}Connect" 或 "connect/{providerId}Connected" 有任何观点(JSP、Thymeleaf 或其他观点)吗?您在 "connect/status" 有意见吗?如果不是,那么这就是 404 的一种可能性。

在“/connect”路径应答的控制器方法收集应用程序中所有已知提供程序的连接状态信息,然后将其发送到名为 "connect/status" 的视图。对于大多数项目(那些使用 JSP 的项目),这意味着您需要一个名为 "status.jsp" 的 JSP 文件,该文件位于名为“/connect”(相对于您的视图的保存位置)的目录中。

对于提供者,每个提供者需要 2 个文件。例如,如果您正在与 Facebook 打交道,您将请求“/connect/facebook”,控制器将收集连接信息并将其发送到名为 "connect/facebookConnect" 的视图(如果您没有连接)或 "connect/facebookConnected"(如果您有连接)。这意味着(在 JSP 情况下)您需要在“/connect/facebookConnect.jsp”和“/connect/facebookConnected.jsp”处使用 JSPs。

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

下的某个目录中