Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Spring 3 can't able Autowire

  1. #1
    Join Date
    Jan 2013
    Posts
    6

    Default Spring 3 can't able Autowire

    Am using both mixture of HIBERNATE (spring contrainer)and JDBC(programtical) with SPRING framework
    Am getting the Dependency Injection(DI) for Hibernate Module and the same is not working (DI) for my JDBC connection modules

    I have the following defined class as below
    *******************************
    Code:
    @Controller("delegate")
    public class ProgramDelegate {
    
        @Autowired
        @Qualifier(value="programService")
        private ProgramService programService;
        public void setProgramService(ProgramService programService) {
            this.programService = programService;
        }
    }
    and
    ***
    @Service("programService")
    public class ProgramServiceImpl implements ProgramService{
    
        @Autowired
        private ProgramDao programDao;
    
    
        public void setProgramDao(ProgramDao programDao) {
            this.programDao = programDao;
        }
    }
    and my application-contex
    *******************
    HTML Code:
    <context:component-scan base-package="com.ample.mis.hibernate.*,
                                            com.ample.mis.*.*.daoImpl,
                                            com.ample.mis.*.*.serviceImpl,
                                            com.ample.mis.*.*.delegate,
                                            com.ample.mis.*.*.helper,
                                            com.ample.mis.*.*.action"/>
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="configLocation" value="classpath:com/ample/mis/hibernate/ifcResources/hibernate_configuration/hibernate.cfg.xml" />
    </bean>
    
    
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" >
        <property name="sessionFactory" ref="sessionFactory" />
    </bean> 
    
    <tx:annotation-driven transaction-manager="transactionManager" />
    dis is the error am getting
    *******************
    Code:
    12:00:26,453 SEVERE [javax.enterprise.resource.webcontainer.jsf.application] Error Rendering View[/pages/program.xhtml]: com.sun.faces.mgbean.ManagedBeanCreationException: Cant instantiate class: com.ample.mis.gk.registration.action.Program.
        at com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:193) [:2.0.2-FCS]
        at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:102) [:2.0.2-FCS]
        at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:405) [:2.0.2-FCS]
        at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:267) [:2.0.2-FCS]
        at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:86) [:2.0.2-FCS]
        at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:175) [:1.0.0.Final]
        at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72) [:2.0.2-FCS]
        at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:67) [:6.0.0.Final]
        at org.apache.el.parser.AstValue.getValue(AstValue.java:115) [:6.0.0.Final]
        at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:187) [:6.0.0.Final]
        at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:102) [:2.0.2-FCS]
        at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:190) [:2.0.2-FCS]
        at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:178) [:2.0.2-FCS]
        at javax.faces.component.UISelectItems.getValue(UISelectItems.java:129) [:2.0.2-FCS]
        at org.primefaces.renderkit.InputRenderer.getSelectItems(InputRenderer.java:53) [:]
        at org.primefaces.component.selectonemenu.SelectOneMenuRenderer.encodeMarkup(SelectOneMenuRenderer.java:68) [:]
        at org.primefaces.component.selectonemenu.SelectOneMenuRenderer.encodeEnd(SelectOneMenuRenderer.java:62) [:]
        at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:878) [:2.0.2-FCS]
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1620) [:2.0.2-FCS]
        at javax.faces.render.Renderer.encodeChildren(Renderer.java:168) [:2.0.2-FCS]
        at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:848) [:2.0.2-FCS]
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1613) [:2.0.2-FCS]
        at javax.faces.render.Renderer.encodeChildren(Renderer.java:168) [:2.0.2-FCS]
        at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:848) [:2.0.2-FCS]
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1613) [:2.0.2-FCS]
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616) [:2.0.2-FCS]
        at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:380) [:2.0.2-FCS]
        at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:126) [:2.0.2-FCS]
        at com.Util.CustomViewHandler.renderView(CustomViewHandler.java:101) [:]
        at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:127) [:2.0.2-FCS]
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [:2.0.2-FCS]
        at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) [:2.0.2-FCS]
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313) [:2.0.2-FCS]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324) [:6.0.0.Final]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.Final]
        at com.Util.SessionFilter.doFilter(SessionFilter.java:81) [:]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.0.0.Final]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.Final]
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [:6.0.0.Final]
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) [:6.0.0.Final]
        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.0.0.Final]
        at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) [:1.1.0.Final]
        at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) [:1.1.0.Final]
        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) [:6.0.0.Final]
        at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) [:6.0.0.Final]
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) [:6.0.0.Final]
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:6.0.0.Final]
        at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.0.0.Final]
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:6.0.0.Final]
        at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.0.0.Final]
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:6.0.0.Final]
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [:6.0.0.Final]
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654) [:6.0.0.Final]
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:6.0.0.Final]
        at java.lang.Thread.run(Unknown Source) [:1.7.0_04]
    Caused by: java.lang.NullPointerException
        at com.ample.mis.gk.registration.delegate.ProgramDelegate.search(ProgramDelegate.java:25) [:]
        at com.ample.mis.gk.registration.action.Program.<init>(Program.java:52) [:]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [:1.7.0_04]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) [:1.7.0_04]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) [:1.7.0_04]
        at java.lang.reflect.Constructor.newInstance(Unknown Source) [:1.7.0_04]
        at java.lang.Class.newInstance0(Unknown Source) [:1.7.0_04]
        at java.lang.Class.newInstance(Unknown Source) [:1.7.0_04]
        at com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:188) [:2.0.2-FCS]
        ... 54 more
    but its work when we create an object using NEW operator and can't able with AUTOWIRE

    Thanks in advance
    Last edited by Ranjankp45; Jan 4th, 2013 at 03:30 AM.

  2. #2
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    740

    Default

    Hi!

    This forum is for project Spring Integration.
    But you've got an issue with integration between Spring MVC & JSF 2, so I recommend to ask similar questions here: http://forum.springsource.org/forumdisplay.php?25-Web

    By your stackTrace it looks like you don't have any Spring+JSF integration: I don't see any Spring errors...
    Try take a look here:
    http://static.springsource.org/sprin...aceselresolver
    http://www.onlinetechvision.com/?p=566
    http://www.mkyong.com/jsf2/jsf-2-0-s...ration-example

    Cheers,
    Artem

    P.S.
    By the way: please, use [ CODE ] [ /CODE ] & [ HTML ] [ /HTML ] without whitespaces to show your sources.

  3. #3
    Join Date
    Jan 2013
    Posts
    6

    Default

    Hi,

    the above error stack shows the problem with JSF but the actual problem is am not able to auto-wire dependencies even though context:component-scan scans the component

    and i can able 2 get the dependencies using this code but not able to auto-wire
    Code:
    ApplicationContext context =  new ClassPathXmlApplicationContext("applicationContext.xml");
    ProgramService service = context.getBean("programService");
    Last edited by Ranjankp45; Jan 4th, 2013 at 03:29 AM.

  4. #4
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    740

    Default

    Do you really think you get all with this what you want ?
    HTML Code:
    <context:component-scan base-package="com.ample.mis.hibernate.*,
    com.ample.mis.*.*.daoImpl,
    com.ample.mis.*.*.serviceImpl,
    com.ample.mis.*.*.delegate,
    com.ample.mis.*.*.helper,
    com.ample.mis.*.*.action"/>
    How about to eat all?
    HTML Code:
    <context:component-scan base-package="com.ample.mis"/>
    Try to play with original suggestion: http://static.springsource.org/sprin...-autodetection and the next section.

  5. #5
    Join Date
    Jan 2013
    Posts
    6

    Default

    Hi Cleric,

    i already tried but its not working too

  6. #6
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    740

    Default

    So, let's try to localize and minimize the boundaries.
    You say you can get "programService" bean from context, but it isn't Autowired with ProgramDao. Right?
    Does your spring context see this component for bean potential?
    How about to define ProgramDao as XML-bean definition instead of annotations...
    Can you show an Exception about attempt to get the "programService" bean?

  7. #7
    Join Date
    Jan 2013
    Posts
    6

    Default

    1.No, ProgramServiceImpl is auto-wired with ProgramDaoImpl
    2. I have tired to configure ProgramDaoImpl in xml, i can get bean (ProgramDaoImpl) but can't able to auto-wire in ProgramServiceImpl

    Code:
    Caused by: java.lang.NullPointerException
    	at com.ample.mis.gk.registration.delegate.ProgramDelegate.search(ProgramDelegate.java:33) [:]
    	at com.ample.mis.gk.registration.action.Program.<init>(Program.java:52) [:]
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [:1.7.0_04]
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) [:1.7.0_04]
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) [:1.7.0_04]
    	at java.lang.reflect.Constructor.newInstance(Unknown Source) [:1.7.0_04]
    	at java.lang.Class.newInstance0(Unknown Source) [:1.7.0_04]
    	at java.lang.Class.newInstance(Unknown Source) [:1.7.0_04]
    	at com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:184) [:2.0.3-SNAPSHOT]
    	... 55 more
    in ProgramDelegate i have a method called "search"
    Last edited by Ranjankp45; Jan 4th, 2013 at 03:31 AM.

  8. #8
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    740

    Default

    i can get bean (ProgramDaoImpl) but can't able to auto-wire in ProgramServiceImpl
    How many beans of ProgramDao implementation do you have?
    How about to mark it with @Qualifier ?

  9. #9
    Join Date
    Jan 2013
    Posts
    6

    Default

    1.i have only one
    2.its just a try which i made

  10. #10
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    740

    Default

    Show, please, Spring Exceptions when you try to get bean from context. You still continue to show JSF error...
    Try to call your @Controller like this:
    Code:
    ApplicationContext ctx = FacesContextUtils.getWebApplicationContext(facesContext);
    ProgramDelegate delegate = ctx.getBean("delegate", ProgramDelegate.class);
    delegate.search(...);
    Of course, if you don't do Spring+JSF integration you should try to use this one WebApplicationContextUtils.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •