近期在项目上,遇到了一个问题。在配置applicationContext.xml使用<import>标签引入其他的xml文件时,导致项目启动时过慢。有时还会引起启动异常。后来查到是xml文件头中的设置问题,尽管不太知道标签头的作用,但还是和大家分享一下经验:

applicationContext.xml文件。仅仅贴出了部分代码:

<!-- 文件头-->
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans

        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<!-- 注入baseDAO层,用于其他的spring.xml文件继承 -->  
    <bean id="baseDao" class="framework.base.BaseDao">  
        <property name="sqlMapClient" ref="sqlMapClient" />  
    </bean> 

<import resource="com/shipment/dao/shipmentSpring.xml" />

引入的shipmentSpring.xml文件:

     

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMTUxMTY4NA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />

大家能够看到。第二个文件shipmentSpring.xml中的文件头,xsi:schemaLocation多了两行出来

以下是启动时控制台的信息,贴出部分异常的信息:

org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 78; schema_reference.4: 无法读取方案文档 'http://www.springframework.org/schema/beans/spring-beans-3.0.xsd', 原由于 1) 无法找到文档; 2) 无法读取文档; 3) 文档的根元素不是 <xsd:schema>。

Caused by: java.net.SocketException: Software caused connection abort: recv failed

五月 12, 2014 9:55:49 上午 org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from relative location [com/shipment/dao/shipmentSpring.xml]
Offending resource: class path resource [applicationContext.xml]; nested exception is org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:
Line 9 in XML document from class path resource [com/shipment/dao/shipmentSpring.xml] is invalid; nested exception is org.xml.sax.SAXParseException;
lineNumber: 9; columnNumber: 78; cvc-elt.1: 找不到元素 'beans' 的声明。

Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:
Line 9 in XML document from class path resource [com/shipment/dao/shipmentSpring.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 78; cvc-elt.1:
找不到元素 'beans' 的声明。

Caused by: org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 78; cvc-elt.1: 找不到元素 'beans' 的声明。

启动时,控制后常常停留在以下两行位置:

大家能够看到我用红色标注的字体,全都是第9行。再看看shipmentSpring.xml文件的第9 行。一開始我注意到这里,后来我将applicationContext.xml的文件头拷贝到shipmentSpring.xml里。将shipmentSpring.xml原来的文件头删除了,项目就能正常启动了,且启动速度快非常多

五月 12, 2014 10:08:22 上午 org.apache.catalina.startup.Catalina start
INFO: Server startup in 7933 ms

原来的启动速度(这是原来的配置正常启动的速度。异常时启动完毕的时间30多秒):

五月 12, 2014 9:55:50 上午 org.apache.catalina.startup.Catalina start
INFO: Server startup in 21174 ms  

说明一下:这两个文件的文件头我都是在别人的项目那里复制过来的,别人那里能正常启动,且启动完毕时间也是10秒内。

文件头的作用(不知道对不正确,大家自己去查查):我印象中好像是在指定的路径里找到对应的文件,也起到限制标签书写是否正确的作用

    

SSH applicationContext.xml import异常的更多相关文章

  1. SSH applicationContext.xml文件配置

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  2. 关于“Could not open ServletContext resource [/WEB-INF/applicationContext.xml]”解决方案

    问题说明,我在web.xml文件中进行了如下配置 <servlet> <servlet-name>dispatcherServlet</servlet-name> ...

  3. SSH整合,applicationContext.xml中配置hibernate映射文件问题

    今天在applicationContext.xml中配置sessionFactory时遇到了各种头疼的问题,现在总结一下: 1.<property name="mappingDirec ...

  4. spring的applicationContext.xml配置SessionFactory抛异常

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFa ...

  5. 事务配置在applicationContext.xml文件中不起作用,控制不了异常回滚

    一.博主在学习到整合ssm框架的时候,遇到一个奇葩的问题就是将 事务的控制 ,写在在applicationContext.xml文件中不起作用,在事务控制的方法中,即使出现了异常,但是事务不会回滚的坑 ...

  6. SSH项目练习的时候报错:[applicationContext.xml]: Invocation of init method failed;

    这里是控制台的报错信息:org.springframework.beans.factory.BeanCreationException: Error creating bean with name ' ...

  7. [JavaEE] applicationContext.xml配置文件使用合集

    配置实例 – 1 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http ...

  8. applicationContext.xml配置AOP切面编程

    Computer.java package com.wh.aop2; public class Computer { public void play01(){ System.out.println( ...

  9. applicationContext.xml和web.xml的一些配置

    applicationContext.xml <!-- test环境 --> <beans profile="test"> <context:prop ...

随机推荐

  1. sqoop import 和export的问题

    sqoop import DB 2 hive(hdfs)是采用JDBC的过程,与传统hive区别在与多走了thrift server接口(稳定性待学习现在还比较模糊没做过大数据量测试),而export ...

  2. LINUX运行级别的原理

    在目录 /etc/rc.d/init.d 下有许多服务器脚本程序,一般称为服务(service), 在 /etc/rc.d 下有 7 个名为 rcN.d 的目录,其中 N=0-6,对应于系统的 7 个 ...

  3. [原创]最优化/Optimization文章合集

    转载请注明出处:https://www.codelast.com/ 最优化(Optimization)是应用数学的一个分支,它是研究在给定约束之下如何寻求某些因素(的量),以使某一(或某些)指标达到最 ...

  4. html 输入框显示“小叉叉”的清空方法

    在IE10以下,我们的输入框input会出现小叉叉.怎么解决这个问题呢? 针对input框我们做一个处理 <style type="text/css"> input:: ...

  5. Python中的一些模块用法

    python中os模块用法 python之模块之shutil模块 -------------------------------os模块-------------------------------- ...

  6. 关闭浏览器或者关闭使用window.open打开的页面时添加监听事件

    最近工作中有个需求:点击按钮时打开一个页面,此处取名为page1,打开页面的前提条件是如果有人已经打开过page1页面并且没有关闭时请求ajax判断session是否为空,如果为空则将用户名和文档id ...

  7. myql 配置项

    提高数据插入速度方法 bulk_insert_buffer_size 默认:8M (8*1024*1024) 参考网址:https://stackoverflow.com/questions/2030 ...

  8. gitlab上fork别人的代码后更新的2种解决方式

    1.解决方式1 首先要先确定一下是否建立了主repo的远程源: git remote -v如果里面只能看到你自己的两个源(fetch 和 push),那就需要添加主repo的源: git remote ...

  9. python中os模块简介

    一.什么是os模块 os模块提供了多数操作系统的功能接口函数.当os模块被导入后,它会自适应于不同的操作系统平台,根据不同的平台进行相应的操作,在python编程时,经常和文件.目录打交道,所以离不了 ...

  10. day38 03-Spring的IOC和DI的区别

    在IOC中有一个DI的概念. IOC是控制反转,DI是依赖注入.现在编写的类里面是没有其他的属性的.如果你学过像UML设计的话, 电视没有遥控器,按按钮也可以,但是紧密的那种,像人和四肢,人如果没有了 ...