views:

242

answers:

2

Hi all,

I create a Controller bean to map a dedicated URI.

web.xml file :

    <!-- Spring MVC Servlet (that will route HTTP requests to BlazeDS) -->
 <servlet>
  <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <init-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>/WEB-INF/spring-main-config.xml</param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
 </servlet>

 <!-- We are only using BlazeDS AMF channels to communicate with FlexClient, so let's map URLs accordingly. -->
 <servlet-mapping>
  <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
  <url-pattern>/messagebroker/*</url-pattern>        
 </servlet-mapping>   

        <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring-filter-config.xml</param-value>
        </context-param>

        <listener>
               <listener-class>
                org.springframework.web.context.ContextLoaderListener
               </listener-class>
        </listener>

spring-main-config.xml file :

 <!-- Import configuration base -->
 <import resource="spring-base-config.xml"/>  

 <!-- Flex integration within Spring. -->
 <flex:message-broker services-config-path="/WEB-INF/flex-services-config.xml">
  <flex:remoting-service />
 </flex:message-broker>

 <!-- Session-scoped bean for User Info -->
 <bean class="com.sharehunter.businessservices.common.UserSessionInfo" scope="session">
  <aop:scoped-proxy proxy-target-class="false"/>
 </bean>    

spring-filter-config.xml file :

    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
  <property name="mappings">
   <value>
   /fbauth=myController
   </value>
  </property>
 </bean>

 <bean id="myController" 
  class="myapp.controller.myController" />

My bean controller file :

package myapp.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

    public class MyController extends AbstractController{

    @Autowired
    UserSesson userSession;

    @Autowired
    BusinessLogger logger;

 @Override
 protected ModelAndView handleRequestInternal(HttpServletRequest request,
   HttpServletResponse response) throws Exception {

  // TO DO - Facebook authentication
  return null;
 }
 }

My problem : all my Autowired bean in my Controller bean is already at equal at null. I don't understand where is the issue in my configuration ...

Thank you very much for your help !

Anthony

+1  A: 

You have two different contextx defined (spring-filter-config.xml and spring-main-config.xml), but you should probably only have one. <context:annotation-driven/> is only defined in spring-main-config.xml, and not in spring-filter-config.xml, so any beans defined in spring-filter-config.xml won't be autowired.

You have your controllers defined in spring-filter-config.xml, but controllers are supposed to be associated with the ServiceDispatcherServlet. You need to move the contents of spring-filter-config.xml into spring-main-config.xml, and then remove the ContextLoaderListener - you don't seem to have any proper use for it.

skaffman
Hi Skaffman, in fact <context:annotation-config /> is present in my spring-base-config.xml (import since spring-main-config.xml). So, this annotation should be too in my spring-filter-config.xml ?
Anthony
@Anthony: See edit
skaffman
A: 

Skaffman,

I did your advice :

You need to move the contents of spring-filter-config.xml into spring-main-config.xml, and then remove the ContextLoaderListener - you don't seem to have any proper use for it.

And in my web navigator, when I set my filter address : http://xx.xx.xx.xx:8080/MyApp/fbauth , I have a HTTP error 404 (the ressource asked (/MyApp/fbauth/) is not available.

I tried several way but now i'm loosing to found the solution ...

Thank you very much,

Anthony

Anthony