我试图在我的(maven)spring MVC安全(spring security)应用程序中配置spring social但是当我尝试访问/connect/
或/connect/providerid
时,我总是得到{{1 }}
当我尝试访问时,这是我的Glassfish服务器日志:
error 404
这是我的社交配置类:
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
这是我的WebAppliactionInitializer类:
@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);
}
}
}
我已经检查了pom.xml
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;
}
有人可以帮帮我吗? (我已经尝试过阅读参考代码和展示示例)
感谢
答案 0 :(得分:3)
只是一个猜测,但你恰好在" connect / {providerId} Connect"中有任何观点(JSP,Thymeleaf或其他)。或" connect / {providerId}已连接"?你有"连接/状态" ?如果没有,那么这就是404s的一种可能性。
控制器方法在" / connect"处回答path收集应用程序中所有已知提供程序的连接状态信息,然后将其发送到名为" connect / status"的视图。对于大多数项目(使用JSP的项目),这意味着您需要一个名为" status.jsp"的JSP文件。在名为" / connect"的目录中(相对于您的观点保存的地方)。
对于提供商,您需要为每个提供商提供2个文件。例如,如果您正在与Facebook打交道,那么您将要求" / connect / facebook"并且控制器将收集连接信息并将其发送到名为" connect / facebookConnect" (如果你没有连接)或" connect / facebookConnected" (如果你有连接)。这意味着(在JSP的情况下)你需要在" /connect/facebookConnect.jsp"和" /connect/facebookConnected.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下面的某个目录中。
答案 1 :(得分:0)
当spring无法正确映射模型和视图时,会发生错误PWC6117: File "null" not found
。
在你的控制器类中,你需要有一些配置,比如
return new ModelAndView("WEB_INF/whereverSpringCanFindYourJSP");
希望这有帮助!
祝你好运!