2016-05-25 12 views
3

/connect/linkedinを開こうとしているうちに、SpringがHTMLビューを見つけられず、IMが404を取得できません。レフリーでthat post私はwebappフォルダ内の私のパスをダブルチェックしました。ここに私のSpringSocialConfigSpring Social/connect return HTTP 404

ある
@Configuration 
@EnableSocial 
public class SocialConfig implements SocialConfigurer { 

    @Inject 
    private DataSource dataSource; 

    @Override 
    public void addConnectionFactories(ConnectionFactoryConfigurer connectionFactoryConfigurer, Environment environment) { 
     connectionFactoryConfigurer.addConnectionFactory(new LinkedInConnectionFactory("xxxxxx", "xxxxxx")); 
    } 

    @Override 
    public UserIdSource getUserIdSource() { 
     return new UserIdSource() { 
      @Override 
      public String getUserId() { 
       Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); 
       if (authentication == null) { 
        throw new IllegalStateException("Unable to get a ConnectionRepository: no user signed in"); 
       } 
       return authentication.getName(); 
      } 
     }; 
    } 

    @Bean 
    public ConnectController connectController(ConnectionFactoryLocator connectionFactoryLocator, ConnectionRepository connectionRepository) { 
     return new ConnectController(connectionFactoryLocator, connectionRepository); 
    } 


    @Bean 
    @Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES) 
    public LinkedIn linkedin(ConnectionRepository repository) { 
     Connection<LinkedIn> connection = repository.findPrimaryConnection(LinkedIn.class); 
     return connection != null ? connection.getApi() : null; 
    } 

    @Override 
    public UsersConnectionRepository getUsersConnectionRepository(ConnectionFactoryLocator connectionFactoryLocator) { 
     return new JdbcUsersConnectionRepository(dataSource, connectionFactoryLocator, Encryptors.noOpText()); 
    } 
} 

/linkedinマッピングハンドラ

@Inject 
private ConnectionRepository connectionRepository; 

@Inject 
private LinkedIn linkedIn; 

@Inject 
public HomeController(LinkedIn linkedIn) { 
    this.linkedIn = linkedIn; 
} 

@RequestMapping(value = "/linkedin", method = RequestMethod.GET) 
public String home(Principal currentUser, Model model) { 
    Connection<LinkedIn> connection = connectionRepository.findPrimaryConnection(LinkedIn.class); 
    if (connection == null) { 
     return "redirect:/connect/linkedin"; 
    } 
    model.addAttribute("profile", connection.getApi().profileOperations().getUserProfileFull()); 
    return "linkedin/profile"; 
} 

と私にHomeControllerとビュー enter image description here

私がログに表示されるよう、何かが起こると/connect/*マッピングが発見されたと私のWEBAPPフォルダ。私はThymeleaf 3.0

@Bean 
public ViewResolver viewResolver() { 
    ThymeleafViewResolver resolver = new ThymeleafViewResolver(); 
    resolver.setTemplateEngine(templateEngine()); 
    resolver.setCharacterEncoding("UTF-8"); 
    resolver.setContentType("text/html; charset=UTF-8"); 
    return resolver; 
} 

@Bean 
public TemplateEngine templateEngine() { 
    SpringTemplateEngine engine = new SpringTemplateEngine(); 
    engine.setEnableSpringELCompiler(true); 
    engine.setTemplateResolver(templateResolver()); 
    engine.addDialect(new SpringSecurityDialect()); 
    return engine; 
} 

private ITemplateResolver templateResolver() { 
     SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver(); 
     resolver.setApplicationContext(applicationContext); 
     resolver.setPrefix("/views/"); 
     resolver.setSuffix(".html"); 
     resolver.setTemplateMode(TemplateMode.HTML); 
     resolver.setCharacterEncoding("UTF-8"); 
     resolver.setCacheable(Boolean.parseBoolean(THYMELEAF_CACHE)); 
     return resolver; 
    } 

ディスパッチャ私は春社会からConnection Controllerにブレークポイントを設定

public class WebAppInitializer implements WebApplicationInitializer { 

    private final String APP_SERVLET_NAME = "x"; 
    private final String DISPLAY_NAME = "App"; 

    @Override 
    public void onStartup(ServletContext container) { 
     container.addListener(new ContextLoaderListener(getContext())); 
     CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); 
     characterEncodingFilter.setEncoding("utf-8"); 
     characterEncodingFilter.setForceEncoding(true); 

     container.addFilter("charEncodingFilter", characterEncodingFilter).addMappingForUrlPatterns(null, false, "/*"); 
     container.addFilter("securityFilter", new DelegatingFilterProxy("springSecurityFilterChain")).addMappingForUrlPatterns(null, false, "/*"); 
     container.addFilter("apiFilter", new DelegatingFilterProxy("apiExceptionHandler")); 
     container.addFilter("hidden", new HiddenHttpMethodFilter()); 

     AnnotationConfigWebApplicationContext dispatcherServlet = new AnnotationConfigWebApplicationContext(); 
     dispatcherServlet.register(ServletConfig.class); 

     ServletRegistration.Dynamic dispatcher = container.addServlet(APP_SERVLET_NAME, new DispatcherServlet(dispatcherServlet)); 
     dispatcher.setLoadOnStartup(1); 
     dispatcher.addMapping("/"); 
    } 

    private AnnotationConfigWebApplicationContext getContext() { 
     AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); 
     rootContext.register(JPARepositoryConfig.class, 
       ThymeleafConfig.class, 
       WebSecurityConfig.class, 
       SocialConfig.class, 
       MailConfig.class, 
       MongoRepositoryConfig.class, 
       ServiceConfig.class, 
       CacheConfig.class); 

     rootContext.setDisplayName(DISPLAY_NAME); 
     return rootContext; 
    } 

構成やマッピングされた方法の非を使用してい

[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/connect/{providerId}],methods=[POST]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.connect(java.lang.String,org.springframework.web.context.request.NativeWebRequest) 
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/connect/{providerId}],methods=[GET]}" 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) 
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/connect],methods=[GET]}" onto public java.lang.String org.springframework.social.connect.web.ConnectController.connectionStatus(org.springframework.web.context.request.NativeWebRequest,org.springframework.ui.Model) 
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/connect/{providerId}],methods=[GET],params=[oauth_token]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.oauth1Callback(java.lang.String,org.springframework.web.context.request.NativeWebRequest) 
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/connect/{providerId}],methods=[GET],params=[code]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.oauth2Callback(java.lang.String,org.springframework.web.context.request.NativeWebRequest) 
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/connect/{providerId}],methods=[GET],params=[error]}" 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) 
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/connect/{providerId}],methods=[DELETE]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.removeConnections(java.lang.String,org.springframework.web.context.request.NativeWebRequest) 
[localhost-startStop-1] INFO org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/connect/{providerId}/{providerUserId}],methods=[DELETE]}" 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) 
[local 

呼び出されました。だから、私はアプリの設定が混乱していると思います。

EDIT 私は間違ったスプリングサーブレット構成を持っていました。私は春のソーシャルコントローラをルートサーブレットとして登録しました。

+0

Hey @Jakub、 'spring controller'に' debug log level'を設定できますか? log4j.logger.controller = DEBUG、console – oak

+0

GitHubでこのエラーを複製する簡単なプロジェクトを作成できますか?それはあなたを助けることがより簡単になります。 – Mithun

答えて

0

私の推測では、あなたのapplication.propertiesでspring.social.auto-connection-views=trueが、私は問題があなたの意見の場所だと思います

+0

私はapplication.propertiesファイルをまったく持っていません。私はBootではなく、Spring MVCを使用しています。 –

+0

よく "redirect:/ connect/linkedin"は、このフラグが設定されていない場合、trueに設定されていると、これらのビューにリダイレクトされます。自分のビューを提供して接続する必要があるか、 (私は春のMVCユーザーではないので、そこでは助けてもらえません) – mklimasz

+0

あなたのソーシャルメディアにリダイレクトするために自分のビューを提供する必要があることを確かめてください。このリダイレクトは動作しないはずです。(これはブートでのみ動作するはずですいくつかの隠れたビューと構成を提供するフラグ)。 – mklimasz

2

ファイルが必要になる場合がありますということです。

あなたはsrc/main/webappの下にあり、春はsrc/main/resourcesの下で閲覧しています。

すべてのhtmlファイルをsrc/main/resources/viewsに移動するか、またはsrc/main/webapp/viewsの下を検索するように設定を変更してください。

これをチェックするExample設定はあなたのものと似ていますが、ビューはsrc/main/resourcesフォルダの下にあります。

-1

私はそれが長い時間知っているが、私はこの問題の解決策を見つけたと思う。

問題は、スプリング構成で 'ConnectController'がBeanとして検出されましたが、コントローラとしてマップされていないことです。また、私はConnectControllerクラスのソースをチェックしました。これは、接頭辞とproviderIdに基づいてビュー名を作成することが判明しました。この回答に続き

:私はConnectControllerを継承し、現在はWEB-INFフォルダ内のFreemarkersテンプレートを指して、 'connectView' と 'connectedView' の両方をオーバーライドしましhttps://stackoverflow.com/a/19699607/4544269

@Controller 
public class CustomConnectController extends ConnectController{ 

    @Autowired 
    public CustomConnectController(
      ConnectionFactoryLocator connectionFactoryLocator, 
      ConnectionRepository connectionRepository) { 
     super(connectionFactoryLocator, connectionRepository); 
    } 

    @Override 
    protected String connectedView(String providerId){ 
     return "connect/facebookConnected"; 
    } 

    @Override 
    protected String connectView(String providerId) { 
     return "connect/facebookConnect"; 
    } 

    } 
関連する問題