Announcement Announcement Module
Collapse
No announcement yet.
@Autowired issue Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @Autowired issue

    Hi,
    I am trying to autowire a Spring Portlet Controller and i get a Unsatisfied dependency error.

    This is what i have in the xml file :

    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
    <bean class="org.springframework.web.portlet.mvc.annotat ion.DefaultAnnotationHandlerMapping">
    <property name="interceptors">
    <!-- This interceptor forwards the mapping request parameter from an ActionRequest to be used as a render parameter. -->
    <bean class="org.springframework.web.portlet.handler.Par ameterMappingInterceptor"/>
    </property>
    </bean>
    <context:component-scan base-package="com.travel"/>
    <context:annotation-config />
    <bean id="gateAndTimeController" class="com.travel.nrtp.controller.GateAndTimeContr oller"/>

    <bean id ="test" class = "com.travel.nrtp.util.Test"/>


    </beans>


    The controller code is like this :

    @Controller
    @RequestMapping("VIEW")

    public class GateAndTimeController
    {
    @Autowired
    private Test test;

    I have also tried to provide the setter for the above field.

    the autowiring fails. Is there something that i am missing.

    Thanks in advance

  • #2
    When you say "the autowiring fails", what exactly happens? Do you get specific exceptions? If so, what exactly do you see?

    Are you certain that the "Test" instance variable is of type "com.travel.nrtp.util.Test"? You didn't show your imports.

    Comment


    • #3
      this is the error

      This is the import

      import com.travel.nrtp.util.Test; so that part is fine.

      The error that i get when i try to deploy the App on the server is :

      SEVERE: WebModule[/GateAndTime]PWC1275: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListe ner
      org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'gateAndTimeController': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Could not autowire field: private com.travel.nrtp.util.Test com.travel.nrtp.controller.GateAndTimeController.t est; nested exception is org.springframework.beans.factory.NoSuchBeanDefini tionException: No unique bean of type [com.travel.nrtp.util.Test] is defined: Unsatisfied dependency of type [class com.travel.nrtp.util.Test]: expected at least 1 matching bean
      at org.springframework.beans.factory.annotation.Autow iredAnnotationBeanPostProcessor.postProcessAfterIn stantiation(AutowiredAnnotationBeanPostProcessor.j ava:280)

      Comment


      • #4
        Are you just missing the context namespace in your <beans ... > element?

        Code:
        <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">

        Comment


        • #5
          tried that still get the same error

          Thanks. I tired with the namespace edition in the xml and i still get the same error.

          Comment


          • #6
            Show us the complete current state of your Spring XML and Java source file.

            Comment


            • #7
              config files and classes

              1. Web.xml :

              <?xml version="1.0" encoding="UTF-8"?>
              <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
              <display-name>Spring Travel Portal</display-name>

              <description>
              Spring Portlet MVC for Travel Applications
              </description>

              <!--
              - The ViewRendererServlet acts as a bridge from Portlet requests to Servlet requests.
              - Thus a Spring Portlet is able to leverage Spring MVC's view rendering capabilities.
              -->
              <servlet>
              <servlet-name>viewRendererServlet</servlet-name>
              <servlet-class>
              org.springframework.web.servlet.ViewRendererServle t
              </servlet-class>
              <load-on-startup>1</load-on-startup>
              </servlet>

              <servlet-mapping>
              <servlet-name>viewRendererServlet</servlet-name>
              <url-pattern>/WEB-INF/servlet/view</url-pattern>
              </servlet-mapping>

              <listener>
              <listener-class>
              org.springframework.web.context.ContextLoaderListe ner
              </listener-class>
              </listener>

              <context-param>
              <param-name>contextConfigLocation</param-name>
              <param-value>/WEB-INF/context/common.xml</param-value>
              </context-param>
              </web-app>

              2. Portlet.xml

              <portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" version="2.0">
              <portlet>
              <portlet-name>GateAndTime</portlet-name>
              <portlet-class>
              org.springframework.web.portlet.DispatcherPortlet
              </portlet-class>
              <init-param>
              <name>contextConfigLocation</name>
              <value>/WEB-INF/context/GateAndTime-portlet.xml</value>
              </init-param>
              <supports>
              <mime-type>text/html</mime-type>
              <portlet-mode>view</portlet-mode>
              <portlet-mode>edit</portlet-mode>
              <portlet-mode>help</portlet-mode>
              </supports>
              <portlet-info>
              <title>GateAndTime</title>
              </portlet-info>
              </portlet>
              </portlet-app>


              So the web.xml points to a common.xml for the contextConfigLocation and the portlet.xml points to a gateAndTime-portlet.xml

              So here are the files:

              common.xml :

              <?xml version="1.0" encoding="UTF-8"?>
              <beans xmlns="http://www.springframework.org/schema/beans"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xmlns="http://www.springframework.org/schema/p"
              xmlns:context="http://www.springframework.org/schema/context"
              xsi:schemaLocation="
              http://www.springframework.org/schema/beans
              http://www.springframework.org/schem...-beans-3.0.xsd
              http://www.springframework.org/schema/context
              http://www.springframework.org/schema/context/spring-context-3.0.xsd">
              <context:component-scan base-package="com.travel"/>
              <bean class="org.springframework.web.portlet.mvc.annotat ion.AnnotationMethodHandlerAdapter"/>
              <bean class="org.springframework.web.portlet.mvc.annotat ion.DefaultAnnotationHandlerMapping"/>
              <!-- Default View Resolver -->
              <bean id="viewResolver" class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
              <property name="viewClass" value="org.springframework.web.servlet.view.JstlVi ew"/>
              <property name="prefix" value="/WEB-INF/jsp/"/>
              <property name="suffix" value=".jsp"/>
              </bean>
              </beans>


              GateAndTime-portlet.xml :

              <beans xmlns="http://www.springframework.org/schema/beans"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xmlns:context="http://www.springframework.org/schema/context"
              xsi:schemaLocation="http://www.springframework.org/schema/beans
              http://www.springframework.org/schem...-beans-3.0.xsd
              http://www.springframework.org/schema/context
              http://www.springframework.org/schema/context/spring-context.xsd">
              <bean class="org.springframework.web.portlet.mvc.annotat ion.DefaultAnnotationHandlerMapping">
              <property name="interceptors">
              <!-- This interceptor forwards the mapping request parameter from an ActionRequest to be used as a render parameter. -->
              <bean class="org.springframework.web.portlet.handler.Par ameterMappingInterceptor"/>
              </property>
              </bean>
              <context:component-scan base-package="com.travel"/>
              <context:annotation-config />
              <bean id="gateAndTimeController" class="com.travel.nrtp.controller.GateAndTimeContr oller"/>

              <bean id ="test" class = "com.travel.nrtp.util.Test"/>


              </beans>

              So we can say the GateAndTime-portlet.xml is a local config and common.xml is more global.

              Here is the GateAndTimeController.java class :

              import com.travel.nrtp.util.Test;
              import java.net.Authenticator;
              import org.springframework.beans.factory.annotation.Autow ired;
              import org.springframework.stereotype.Controller;
              import org.springframework.ui.Model;
              import org.springframework.ui.ModelMap;
              import org.springframework.validation.BindingResult;
              import org.springframework.web.bind.annotation.ModelAttri bute;
              import org.springframework.web.bind.annotation.RequestMap ping;
              import org.springframework.web.bind.annotation.RequestPar am;
              import org.springframework.web.bind.annotation.SessionAtt ributes;
              import org.springframework.web.bind.support.SessionStatus ;
              import org.springframework.web.portlet.bind.annotation.Ac tionMapping;
              import org.springframework.web.portlet.bind.annotation.Re nderMapping;
              import java.text.*;
              import java.util.*;
              import org.springframework.beans.factory.annotation.Quali fier;


              @Controller
              @RequestMapping("VIEW")

              public class GateAndTimeController
              {
              @Autowired
              private Test test;

              public GateAndTimeController()
              {
              Authenticator.setDefault(new ProxyAuthenticator("900587","mitu@2608"));

              Properties p = System.getProperties();
              p.setProperty("http.proxyHost","proxy.aa.com");
              p.setProperty("http.proxyPort", "80");
              System.setProperties(p);


              }

              @RenderMapping
              public String displayPage(ModelMap model)
              {
              model.addAttribute("gtdetails", new GateAndTimeInfo());
              System.out.println("In the controller to display the page");
              String s =test.print();
              System.out.println("the test print is:"+s);
              return "view";
              }

              @ActionMapping(params ="action=fetch")
              public void fetchInfo(ActionRequest request, ActionResponse response, @ModelAttribute("gtdetails") GateAndTimeInfo gtInfo, Model model)
              {
              System.out.println("Fetch the Gate and Time info for Flight ");

              if(request.getParameter("gt")!=null)
              {
              System.out.println("Got the button value");
              String flt = gtInfo.getFlightNumber();
              String date = gtInfo.getDate();
              System.out.println("the flight number is :"+flt);
              System.out.println("the date :"+date);

              gtInfo.setTime("6:30");
              gtInfo.setGate("24");
              gtInfo.setTerminal("D");

              DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
              Date d =null;
              try
              {
              d = formatter.parse(date);
              }
              catch (ParseException ex)
              {
              System.out.println("Exception in parsing the date");

              }

              /* GateAndTimeServiceImpl gateAndTimeService = new GateAndTimeServiceImpl();
              List flightList= gateAndTimeService.getGateAndTimeInfo("DFW", "LAX", flt, d);

              */

              }
              model.addAttribute("flightInfo", gtInfo);
              response.setRenderParameter("action", "gntinfo");

              }
              @RenderMapping(params = "action=gntinfo")
              public String displayGateAndTimeInfo(ModelMap model)
              {
              GateAndTimeInfo form = (GateAndTimeInfo)model.get("flightInfo");
              model.addAttribute("result", form);

              System.out.println("Display the Gate and Time info");
              return "view";
              }

              }

              The test.java is a simple java class with nothing in it.


              Thanks for help.

              Comment


              • #8
                config files

                1. web.xml

                <?xml version="1.0" encoding="UTF-8"?>
                <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
                <display-name>Spring Travel Portal</display-name>

                <description>
                Spring Portlet MVC for Travel Applications
                </description>

                <!--
                - The ViewRendererServlet acts as a bridge from Portlet requests to Servlet requests.
                - Thus a Spring Portlet is able to leverage Spring MVC's view rendering capabilities.
                -->
                <servlet>
                <servlet-name>viewRendererServlet</servlet-name>
                <servlet-class>
                org.springframework.web.servlet.ViewRendererServle t
                </servlet-class>
                <load-on-startup>1</load-on-startup>
                </servlet>

                <servlet-mapping>
                <servlet-name>viewRendererServlet</servlet-name>
                <url-pattern>/WEB-INF/servlet/view</url-pattern>
                </servlet-mapping>

                <listener>
                <listener-class>
                org.springframework.web.context.ContextLoaderListe ner
                </listener-class>
                </listener>

                <context-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>/WEB-INF/context/common.xml</param-value>
                </context-param>
                </web-app>


                2. Portlet.xml

                <portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" version="2.0">
                <portlet>
                <portlet-name>GateAndTime</portlet-name>
                <portlet-class>
                org.springframework.web.portlet.DispatcherPortlet
                </portlet-class>
                <init-param>
                <name>contextConfigLocation</name>
                <value>/WEB-INF/context/GateAndTime-portlet.xml</value>
                </init-param>
                <supports>
                <mime-type>text/html</mime-type>
                <portlet-mode>view</portlet-mode>
                <portlet-mode>edit</portlet-mode>
                <portlet-mode>help</portlet-mode>
                </supports>
                <portlet-info>
                <title>GateAndTime</title>
                </portlet-info>
                </portlet>
                </portlet-app>


                The web.xml points to a common.xml as the ContextConfigLocation and the portlet.xml points to GateAndTime-portlet.xml so we can say common.xml is for the App and GateAndTime-portlet.xml is for this portlet.

                So here are those files:

                3. Common.xml :

                <?xml version="1.0" encoding="UTF-8"?>
                <beans xmlns="http://www.springframework.org/schema/beans"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns="http://www.springframework.org/schema/p"
                xmlns:context="http://www.springframework.org/schema/context"
                xsi:schemaLocation="
                http://www.springframework.org/schema/beans
                http://www.springframework.org/schem...-beans-3.0.xsd
                http://www.springframework.org/schema/context
                http://www.springframework.org/schema/context/spring-context-3.0.xsd">
                <context:component-scan base-package="com.travel"/>
                <bean class="org.springframework.web.portlet.mvc.annotat ion.AnnotationMethodHandlerAdapter"/>
                <bean class="org.springframework.web.portlet.mvc.annotat ion.DefaultAnnotationHandlerMapping"/>
                <!-- Default View Resolver -->
                <bean id="viewResolver" class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
                <property name="viewClass" value="org.springframework.web.servlet.view.JstlVi ew"/>
                <property name="prefix" value="/WEB-INF/jsp/"/>
                <property name="suffix" value=".jsp"/>
                </bean>
                </beans>

                4. GateAndTime-portlet.xml :

                <beans xmlns="http://www.springframework.org/schema/beans"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns:context="http://www.springframework.org/schema/context"
                xsi:schemaLocation="http://www.springframework.org/schema/beans
                http://www.springframework.org/schem...-beans-3.0.xsd
                http://www.springframework.org/schema/context
                http://www.springframework.org/schema/context/spring-context.xsd">
                <bean class="org.springframework.web.portlet.mvc.annotat ion.DefaultAnnotationHandlerMapping">
                <property name="interceptors">
                <!-- This interceptor forwards the mapping request parameter from an ActionRequest to be used as a render parameter. -->
                <bean class="org.springframework.web.portlet.handler.Par ameterMappingInterceptor"/>
                </property>
                </bean>
                <context:component-scan base-package="com.travel"/>
                <context:annotation-config />
                <bean id="gateAndTimeController" class="com.travel.nrtp.controller.GateAndTimeContr oller"/>

                <bean id ="test" class = "com.travel.nrtp.util.Test"/>


                </beans>


                5. GateAndTimeController.java

                import com.travel.nrtp.util.Test;
                import java.net.Authenticator;
                import org.springframework.beans.factory.annotation.Autow ired;
                import org.springframework.stereotype.Controller;
                import org.springframework.ui.Model;
                import org.springframework.ui.ModelMap;
                import org.springframework.validation.BindingResult;
                import org.springframework.web.bind.annotation.ModelAttri bute;
                import org.springframework.web.bind.annotation.RequestMap ping;
                import org.springframework.web.bind.annotation.RequestPar am;
                import org.springframework.web.bind.annotation.SessionAtt ributes;
                import org.springframework.web.bind.support.SessionStatus ;
                import org.springframework.web.portlet.bind.annotation.Ac tionMapping;
                import org.springframework.web.portlet.bind.annotation.Re nderMapping;
                import java.text.*;
                import java.util.*;
                import org.springframework.beans.factory.annotation.Quali fier;


                @Controller
                @RequestMapping("VIEW")

                public class GateAndTimeController
                {
                @Autowired
                private Test test;

                public GateAndTimeController()
                {
                Authenticator.setDefault(new ProxyAuthenticator())

                Properties p = System.getProperties();
                p.setProperty("http.proxyHost","proxy.aa.com");
                p.setProperty("http.proxyPort", "80");
                System.setProperties(p);


                }

                @RenderMapping
                public String displayPage(ModelMap model)
                {
                model.addAttribute("gtdetails", new GateAndTimeInfo());
                System.out.println("In the controller to display the page");
                String s =test.print();
                System.out.println("the test print is:"+s);
                return "view";
                }

                @ActionMapping(params ="action=fetch")
                public void fetchInfo(ActionRequest request, ActionResponse response, @ModelAttribute("gtdetails") GateAndTimeInfo gtInfo, Model model)
                {
                System.out.println("Fetch the Gate and Time info for Flight ");

                if(request.getParameter("gt")!=null)
                {
                System.out.println("Got the button value");
                String flt = gtInfo.getFlightNumber();
                String date = gtInfo.getDate();
                System.out.println("the flight number is :"+flt);
                System.out.println("the date :"+date);

                gtInfo.setTime("6:30");
                gtInfo.setGate("24");
                gtInfo.setTerminal("D");

                DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
                Date d =null;
                try
                {
                d = formatter.parse(date);
                }
                catch (ParseException ex)
                {
                System.out.println("Exception in parsing the date");

                }

                /* GateAndTimeServiceImpl gateAndTimeService = new GateAndTimeServiceImpl();
                List flightList= gateAndTimeService.getGateAndTimeInfo("DFW", "LAX", flt, d);

                */

                }
                model.addAttribute("flightInfo", gtInfo);
                response.setRenderParameter("action", "gntinfo");

                }
                @RenderMapping(params = "action=gntinfo")
                public String displayGateAndTimeInfo(ModelMap model)
                {
                GateAndTimeInfo form = (GateAndTimeInfo)model.get("flightInfo");
                model.addAttribute("result", form);

                System.out.println("Display the Gate and Time info");
                return "view";
                }

                }

                Thanks for the help
                Last edited by sriuday; Oct 27th, 2009, 07:54 PM.

                Comment


                • #9
                  I tried a stripped-down version of your code, and I did not receive the error. Could you post your entire stack trace?

                  Comment


                  • #10
                    stack trace

                    SEVERE: Context initialization failed
                    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'gateAndTimeController': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Could not autowire field: private com.travel.nrtp.util.Test com.travel.nrtp.controller.GateAndTimeController.t est; nested exception is org.springframework.beans.factory.NoSuchBeanDefini tionException: No unique bean of type [com.travel.nrtp.util.Test] is defined: Unsatisfied dependency of type [class com.travel.nrtp.util.Test]: expected at least 1 matching bean
                    at org.springframework.beans.factory.annotation.Autow iredAnnotationBeanPostProcessor.postProcessAfterIn stantiation(AutowiredAnnotationBeanPostProcessor.j ava:280)
                    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:1011)
                    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:511)
                    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:450)
                    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 89)
                    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
                    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:286 )
                    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:188)
                    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:543)
                    at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:730)
                    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:387)
                    at org.springframework.web.context.ContextLoader.crea teWebApplicationContext(ContextLoader.java:270)
                    at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:197)
                    at org.springframework.web.context.ContextLoaderListe ner.contextInitialized(ContextLoaderListener.java: 47)
                    at org.apache.catalina.core.StandardContext.listenerS tart(StandardContext.java:4623)
                    at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:5323)
                    at com.sun.enterprise.web.WebModule.start(WebModule.j ava:456)
                    at org.apache.catalina.core.ContainerBase.addChildInt ernal(ContainerBase.java:922)
                    at org.apache.catalina.core.ContainerBase.addChild(Co ntainerBase.java:906)
                    at org.apache.catalina.core.StandardHost.addChild(Sta ndardHost.java:696)
                    at com.sun.enterprise.web.WebContainer.loadWebModule( WebContainer.java:2205)
                    at java.util.TimerThread.mainLoop(Timer.java:512)
                    at java.util.TimerThread.run(Timer.java:462)
                    Caused by: org.springframework.beans.factory.BeanCreationExce ption: Could not autowire field: private com.travel.nrtp.util.Test com.travel.nrtp.controller.GateAndTimeController.t est; nested exception is org.springframework.beans.factory.NoSuchBeanDefini tionException: No unique bean of type [com.travel.nrtp.util.Test] is defined: Unsatisfied dependency of type [class com.travel.nrtp.util.Test]: expected at least 1 matching bean
                    at org.springframework.beans.factory.annotation.Autow iredAnnotationBeanPostProcessor$AutowiredFieldElem ent.inject(AutowiredAnnotationBeanPostProcessor.ja va:497)
                    at org.springframework.beans.factory.annotation.Injec tionMetadata.injectFields(InjectionMetadata.java:1 05)
                    at org.springframework.beans.factory.annotation.Autow iredAnnotationBeanPostProcessor.postProcessAfterIn stantiation(AutowiredAnnotationBeanPostProcessor.j ava:277)
                    ... 37 more
                    Caused by: org.springframework.beans.factory.NoSuchBeanDefini tionException: No unique bean of type [com.travel.nrtp.util.Test] is defined: Unsatisfied dependency of type [class com.travel.nrtp.util.Test]: expected at least 1 matching bean
                    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.doResolveDependency(DefaultList ableBeanFactory.java:751)
                    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.resolveDependency(DefaultListab leBeanFactory.java:666)
                    at org.springframework.beans.factory.annotation.Autow iredAnnotationBeanPostProcessor$AutowiredFieldElem ent.inject(AutowiredAnnotationBeanPostProcessor.ja va:468)
                    ... 39 more
                    SEVERE: WebModule[/GateAndTime]PWC1275: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListe ner
                    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'gateAndTimeController': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Could not autowire field: private com.travel.nrtp.util.Test com.travel.nrtp.controller.GateAndTimeController.t est; nested exception is org.springframework.beans.factory.NoSuchBeanDefini tionException: No unique bean of type [com.travel.nrtp.util.Test] is defined: Unsatisfied dependency of type [class com.travel.nrtp.util.Test]: expected at least 1 matching bean
                    at org.springframework.beans.factory.annotation.Autow iredAnnotationBeanPostProcessor.postProcessAfterIn stantiation(AutowiredAnnotationBeanPostProcessor.j ava:280)
                    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:1011)
                    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:511)
                    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:450)
                    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 89)
                    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
                    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:286 )
                    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:188)
                    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:543)
                    at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:730)
                    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:387)
                    at org.springframework.web.context.ContextLoader.crea teWebApplicationContext(ContextLoader.java:270)
                    at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:197)
                    at org.springframework.web.context.ContextLoaderListe ner.contextInitialized(ContextLoaderListener.java: 47)
                    at org.apache.catalina.core.StandardContext.listenerS tart(StandardContext.java:4623)
                    at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:5323)
                    at com.sun.enterprise.web.WebModule.start(WebModule.j ava:456)
                    at org.apache.catalina.core.ContainerBase.addChildInt ernal(ContainerBase.java:922)
                    at org.apache.catalina.core.ContainerBase.addChild(Co ntainerBase.java:906)
                    at org.apache.catalina.core.StandardHost.addChild(Sta ndardHost.java:696)
                    at com.sun.enterprise.web.WebContainer.loadWebModule( WebContainer.java:2205)
                    at com.sun.enterprise.web.WebContainer.loadWebModule( WebContainer.java:1890)
                    at com.sun.enterprise.web.WebApplication.start(WebApp lication.java:85)
                    at com.sun.enterprise.v3.server.ApplicationLifecycle. start(ApplicationLifecycle.java:560)
                    at com.sun.enterprise.v3.server.ApplicationLifecycle. start(ApplicationLifecycle.java:547)
                    at com.sun.enterprise.v3.server.ApplicationLifecycle. deploy( at java.util.TimerThread.run(Timer.java:462)
                    Caused by: org.springframework.beans.factory.BeanCreationExce ption: Could not autowire field: private com.travel.nrtp.util.Test com.travel.nrtp.controller.GateAndTimeController.t est; nested exception is org.springframework.beans.factory.NoSuchBeanDefini tionException: No unique
                    ... 39 more
                    SEVERE: PWC1306: Startup of context /GateAndTime failed due to previous errors

                    Comment


                    • #11
                      That's a head-scratcher for sure.

                      Is there anything special about your com.travel.nrtp.util.Test class? It's not abstract or anything like that, is it?

                      Comment


                      • #12
                        Got it to work

                        I got it to work by moving the bean definition of Test :

                        <bean id ="test" class = "com.travel.nrtp.util.Test"/> from the GateAndTime-portlet.xml file to the common.xml file. For autowiring spring seems to only take the common or application file into picture and not the portlet specific file.
                        The strange thing is if i dont use autowiring but use the no wiring using bean definitions i can place both the Controller definition and the Test definition in the GateAndTime-portlet.xml and it works.

                        Comment

                        Working...
                        X