美文网首页
因为在 *.hbm.xml文件的首行写了注释而导致spring

因为在 *.hbm.xml文件的首行写了注释而导致spring

作者: 李北北 | 来源:发表于2018-11-21 19:19 被阅读0次

    今天把一个升级包交给测试后,那边反馈升级后启动失败,看了下日志发现如下异常,于是排查了良久,最后发现罪魁祸首是因为在某个*.hbm.xml(代码在文后)文件首行加了注释!!!最后去了这行注释后就正常了,一下午就过去了哎。。。

    异常信息:

    2018-11-21 17:17:27.984 ERROR [pool-6-thread-3] org.hibernate.util.xml.ErrorLogger.error Error parsing XML (2) : The processing instruction target matching "[xX][mM][lL]" is not allowed.
    2018-11-21 17:17:28.020 ERROR [pool-6-thread-3] org.springframework.web.context.ContextLoader.initWebApplicationContext Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'commonService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.xxxxx.xxx.common.dao.impl.CommonDAO com.xxxxx.xxx.common.service.impl.CommonService.commonDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'commonDAO': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void com.xxxxx.xxx.common.dao.impl.HibernateGenericDao.setSessionFactoryEx(org.hibernate.SessionFactory); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file [D:\Program Files (x86)\SurveillanceSystem\CMS\webserver\Tomcat\webapps\att\WEB-INF\classes\application-context-datasource.xml]: Invocation of init method failed; nested exception is org.hibernate.InvalidMappingException: Unable to read XML
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:293)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1186)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:706)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:762)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
        at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5068)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5584)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
        at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1260)
        at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:566)
        at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1779)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301)
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
        at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
        at com.xxxxx.xxx.deploy.watchdog.adapter.tomcat70.Tomcat70ContainerAdaptor.checkChanges(Tomcat70ContainerAdaptor.java:98)
        at com.xxxxx.xxx.deploy.watchdog.adapter.tomcat70.Tomcat70ContainerAdaptor.installContextInternal(Tomcat70ContainerAdaptor.java:116)
        at com.xxxxx.xxx.deploy.watchdog.AbstractTomcatContainer.installContext(AbstractTomcatContainer.java:65)
        at com.xxxxx.xxx.deploy.watchdog.utils.TomcatContainerUtils.installContext(TomcatContainerUtils.java:68)
        at com.xxxxx.xxx.deploy.watchdog.thread.InstallContextThread.run(InstallContextThread.java:26)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)
    Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.xxxxx.xxx.common.dao.impl.CommonDAO com.xxxxx.xxx.common.service.impl.CommonService.commonDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'commonDAO': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void com.xxxxx.xxx.common.dao.impl.HibernateGenericDao.setSessionFactoryEx(org.hibernate.SessionFactory); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file [D:\Program Files (x86)\SurveillanceSystem\CMS\webserver\Tomcat\webapps\att\WEB-INF\classes\application-context-datasource.xml]: Invocation of init method failed; nested exception is org.hibernate.InvalidMappingException: Unable to read XML
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:509)
        at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:290)
        ... 37 more
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'commonDAO': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void com.xxxxx.xxx.common.dao.impl.HibernateGenericDao.setSessionFactoryEx(org.hibernate.SessionFactory); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file [D:\Program Files (x86)\SurveillanceSystem\CMS\webserver\Tomcat\webapps\att\WEB-INF\classes\application-context-datasource.xml]: Invocation of init method failed; nested exception is org.hibernate.InvalidMappingException: Unable to read XML
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:293)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1186)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1021)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:964)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:862)
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:481)
        ... 39 more
    Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void com.xxxxx.xxx.common.dao.impl.HibernateGenericDao.setSessionFactoryEx(org.hibernate.SessionFactory); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file [D:\Program Files (x86)\SurveillanceSystem\CMS\webserver\Tomcat\webapps\att\WEB-INF\classes\application-context-datasource.xml]: Invocation of init method failed; nested exception is org.hibernate.InvalidMappingException: Unable to read XML
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:597)
        at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:290)
        ... 50 more
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file [D:\Program Files (x86)\SurveillanceSystem\CMS\webserver\Tomcat\webapps\att\WEB-INF\classes\application-context-datasource.xml]: Invocation of init method failed; nested exception is org.hibernate.InvalidMappingException: Unable to read XML
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1554)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1021)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:964)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:862)
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:554)
        ... 52 more
    Caused by: org.hibernate.InvalidMappingException: Unable to read XML
        at org.hibernate.util.xml.MappingReader.readMappingDocument(MappingReader.java:101)
        at org.hibernate.cfg.Configuration.add(Configuration.java:513)
        at org.hibernate.cfg.Configuration.add(Configuration.java:509)
        at org.hibernate.cfg.Configuration.add(Configuration.java:716)
        at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:756)
        at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:625)
        at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:189)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1613)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1550)
        ... 62 more
    Caused by: org.dom4j.DocumentException: Error on line 2 of document  : The processing instruction target matching "[xX][mM][lL]" is not allowed. Nested exception: The processing instruction target matching "[xX][mM][lL]" is not allowed.
        at org.dom4j.io.SAXReader.read(SAXReader.java:482)
        at org.hibernate.util.xml.MappingReader.readMappingDocument(MappingReader.java:75)
        ... 70 more
    

    *.hbm.xml代码

    <!-- 注释 -->   (就是因为这里多了个注释,从而导致dom4j无法解析)
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <!-- Mapping file autogenerated by MyEclipse Persistence Tools -->
    <hibernate-mapping>
        <class name="com.xxx.xxx.Car" table="v_car">
            <comment>过车记录</comment>
            <id name="personId" type="java.lang.Integer">
                <column name="person_id" />
            </id>
            
            <property name="carCrosstime">
                <column name="car_crosstime" length="22" />
            </property>
        </class>
    </hibernate-mapping>
    
    

    相关文章

      网友评论

          本文标题:因为在 *.hbm.xml文件的首行写了注释而导致spring

          本文链接:https://www.haomeiwen.com/subject/ymfhqqtx.html