spring BeanCreationException confusion about mapping

后端 未结 3 1510
失恋的感觉
失恋的感觉 2020-12-18 05:16

trying to integrate hibernate and spring ,I ran into this error

SEVERE: Context initialization failed org.springframework.beans.factory.BeanC

相关标签:
3条回答
  • 2020-12-18 05:46

    Or you can mention <mvc:annotation-driven/> in your XML and remove the

    <context:component-scan base-package="org.me.spring.hib.school.web" /> part.

    If you are comfortable with XML notations.

    0 讨论(0)
  • 2020-12-18 05:54

    I faced similar kind of problem. I have defined the controller class with "@Controller" and also in the Spring-config.xml file as a bean and have injected the dependencies.

    This was causing the problem. @Controller is defining the bean and again, the bean defined in the xml file is redefining the dependencies. I tried autowiring the dependency and removed it as a bean from the xml file. Then it worked.

    0 讨论(0)
  • 2020-12-18 06:07

    This is happening because you have both

    <context:component-scan base-package="org.me.spring.hib.school.web" />
    

    and

    <bean  class="org.me.spring.hib.school.web.SchoolController" >
    

    The first line will auto-discover and register a SchoolController for you. By explicitly declaring another one, you get a duplicate, and the url-mapping will clash.

    You need to either remove the <context:component-scan>, or remove the explicit bean definitions for the controller and the DAO. If you do the latter, then you'll need to use autowiring to inject their dependencies.

    0 讨论(0)
提交回复
热议问题