Java项目中,不同包下有重名的Java文件,启动的时候为什么会报错?
巴扎黑
巴扎黑 2017-04-18 09:16:30
0
4
354

org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/classes/springContext.xml]; nested exception is java.lang.IllegalStateException: Annotation-specified bean name 'cardController' for bean class [com.qdzq.wlpt.controller.api.CardController] conflicts with existing, non-compatible bean definition of same name and class [com.qdzq.wlpt.controller.admin.CardController]

不同包下的文件不是可以重名吗?

巴扎黑
巴扎黑

reply all (4)
小葫芦

You used Spring’s Annotation,@Controller标记的bean的id为类名(首字母小写),这两个CardController的bean id均为cardController, so the id conflict

    黄舟

    You can post your xml file and have a look

      巴扎黑

      You have two CardControllers. After automatic injection, the bean IDs will conflict. If you want both, configure two beans in the spring file and set them to different IDs, so there will be no conflict. Spring defaults to the bean ID. The first letter of the class name is lowercase

        小葫芦

        For Auto-Scan, the Controller does not allow duplicate names by default, as does Service and Dao.
        If the default class is ClassName, the beanID is className.
        You can customize the bean id, @Service("xxxService"), the Controller has not been repeated, and it should be handled in the same way.

          Latest Downloads
          More>
          Web Effects
          Website Source Code
          Website Materials
          Front End Template
          About us Disclaimer Sitemap
          php.cn:Public welfare online PHP training,Help PHP learners grow quickly!