gpt4 book ai didi

Spring 社交/连接返回 404

转载 作者:行者123 更新时间:2023-12-02 03:41:39 31 4
gpt4 key购买 nike

我正在尝试在我的(maven)spring MVC secure(spring security)应用程序中配置springsocial,但是当我尝试访问/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”上有任何 View (JSP、Thymeleaf 或其他)?您可以查看“连接/状态”吗?如果没有,那么这就是 404 的一种可能性。

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

对于提供商,每个提供商需要 2 个文件。例如,如果您正在与 Facebook 打交道,您将请求“/connect/facebook”, Controller 将收集连接信息并将其发送到名为“connect/facebookConnect”的 View (如果您没有连接) )或“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 下的某个目录中。

关于 Spring 社交/连接返回 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30249204/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com