Spring-Social/Twitter -- ConnectController doesn't respond to /connect? Spring-Social/Twitter -- ConnectController doesn't respond to /connect? spring spring

Spring-Social/Twitter -- ConnectController doesn't respond to /connect?


Your ConnectController is in the wrong configuration file. You should move it to the legototies-servlet.xml.

The used HandlerMapping implementations only detect (@)Controller beans in the local context (the one loaded by the DispatcherServlet) NOT in the parent context (loaded by the ContextLoaderListener). So your ConnectController is configured but isn't doing anything because it isn't detected.

There is also another problem with your configuration, you are loading all the beans twice. This is due to the way you have configured component scanning. In both configuration files there is a <context:component-scan base-package="com.lt" /> which basically duplicates all beans. In general you should configure the DispatcherServlet to load only @Controllers and the ContextLoaderListener to load everything BUT @Controllers.

<context:component-scan base-package="com.lt">    <context:exclude-filter type="annotation" value="org.springframework.stereotype.Controller" /></context:component-scan>

and for the DispatcherServlet

<context:component-scan base-package="com.lt" use-default-filters="false">    <context:include-filter type="annotation" value="org.springframework.stereotype.Controller" /></context:component-scan>

And at first glance you also have an error in your database configuration. You are using hibernate but have configured a DataSourceTransactionManager whereas you should configure a HibernateTransactionManager. The latter is perfectly capable of controlling plain JDBC transactions.


Here you need to override some methods from ConnectController. Here I give you some code snippet (commented) which might be useful to you. The default view for the ConnectController is /connect/{providerID}Connected - once authorized and connected & /connect/{providerID}Connect - once disconnect this is the default view. You are getting 404 Error because, you don't have connect folder and twitterConnected.jsp inside that. Just to test you create a connect folder and put 1.twitterConnected.jsp and 2.twitterConnect.jsp inside that and try connecting it before you subclass your ConnectController as shown below.

@Controllerpublic class CustomConnectController extends ConnectController {    @Inject    public CustomConnectController(            ConnectionFactoryLocator connectionFactoryLocator,            ConnectionRepository connectionRepository) {        super(connectionFactoryLocator, connectionRepository);    }    //This connectedView will be called after user authorize twitter app.  So here you can redirect       //users to the page you need.    @Override    protected String connectedView(String providerId){        return "redirect:/user/profile";    }    //This connectView will be called if user disconnect from social media.  Here you can redirect     //them once they got disconnected.      @Override    protected String connectView(String providerId) {        return "redirect:/connect";    }}

Just try it and let me know your output.


1) Goes on top of web.xml ( you want security filter to be first guy to get the request)

 <filter>        <filter-name>springSecurityFilterChain</filter-name>        <filter-class>            org.springframework.web.filter.DelegatingFilterProxy        </filter-class>    </filter>    <filter-mapping>        <filter-name>springSecurityFilterChain</filter-name>        <url-pattern>/*</url-pattern>    </filter-mapping>

2) you are using tiles, so you wont be using jsp view resolver. change it to

<bean id="viewResolver"        class="org.springframework.web.servlet.view.UrlBasedViewResolver">        <property name="viewClass"            value="org.springframework.web.servlet.view.tiles2.TilesView" />    </bean>

3)servlet name has to match your servlet config file name.

EDIT: Also proper way to load context

  <servlet>            <servlet-name>appServlet</servlet-name>            <servlet-class>org.springframework.web.servlet.DispatcherServlet            </servlet-class>            <init-param>                <param-name>contextConfigLocation</param-name>                <param-value>/WEB-INF/appServlet-context.xml</param-value>            </init-param>            <load-on-startup>1</load-on-startup>        </servlet>

change appServlet to your servlet config file.