春季社交/连接返回404

我正在尝试在我的(maven)春季MVC保护的(春季安全性)应用程序中配置spring社交,但是当我尝试访问/ connect /或/ connect / providerid时,总是出现错误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

这是我的社交配置类:

@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类:

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>

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

解决方法:

只是一个猜测,但是您是否对“ connect / {providerId} Connect”或“ connect / {providerId} Connected”有任何见解(JSP,Thymeleaf或其他)?您是否有“连接/状态”视图?如果没有,那是404机的一种可能性.

在“ / connect”路径处应答的控制器方法收集应用程序中所有已知提供程序的连接状态信息,然后将其发送到名为“ connect / status”的视图中.对于大多数项目(那些使用JSP的项目),这意味着您需要在名为“ / connect”(相对于保留视图的位置)的目录中名为Jstat文件“ status.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下的某个目录中.

上一篇:部署WAR时,glassfish无法找到我的wsdl


下一篇:Java-HTTP错误404请求的资源不可用,Glassfish