问题
I'm trying to configure spring social inside my (maven)spring MVC secured(spring security) application but when I try to access /connect/
or /connect/providerid
, I always get error 404
Here is my Glassfish server log when I try to access:
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
Here is my social config 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);
}
}
Here is my 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;
}
}
I already checked the 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>
Someone can help me? (I've already tried to read the reference code and the showcase examples) Thanks
回答1:
Just a guess, but do you happen to have any views (JSP, Thymeleaf, or otherwise) at "connect/{providerId}Connect" or "connect/{providerId}Connected"? Do you have a view at "connect/status" ? If not, then that's one possibility for the 404s.
The controller method answering at the "/connect" path collects connection status information for all known providers in the app and then sends that on to a view named "connect/status". For most projects (those using JSP), this means that you need a JSP file named "status.jsp" in a directory named "/connect" (relative to where your views are kept).
For a provider, you'll need 2 files for each provider. For example, if you're dealing with Facebook, you'll request "/connect/facebook" and the controller will collect connection information and send it on to a view named "connect/facebookConnect" (if you don't have a connection) or "connect/facebookConnected" (if you do have a connection). This means (in the JSP case) you'll need JSPs at "/connect/facebookConnect.jsp" and "/connect/facebookConnected.jsp".
Take a look at https://github.com/spring-projects/spring-social-samples/tree/master/spring-social-showcase. This example uses Thymeleaf instead of JSP, but it demonstrates the basic idea. You'll find the templates in src/main/resources/views/connect. If this was a JSP-viewed application, you'd likely put them in src/main/webapp or some directory underneath src/main/webapp.
回答2:
the error PWC6117: File "null" not found
occurs when spring is not able to properly map the model and views.
In your controller class you need to have some configuration like
return new ModelAndView("WEB_INF/whereverSpringCanFindYourJSP");
- Cryptic jetty-maven-plugin error message 'ERROR: PWC6117: File "null" not found'
hope this helps!
Good luck!
来源:https://stackoverflow.com/questions/30249204/spring-social-connect-return-404