近期在项目上,遇到了一个问题。在配置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. Python基础---三大推导式

    推导式comprehensions(又称解析式),是Python的一种独有特性.推导式是可以从一个数据结构构建另一个新的数据结构的结构体. 共有三种推导,在Python2和3中都有支持: 列表(lis ...

  2. Hibernate-概述-搭建-测试-配置详解

    一 hibernate概述 1.1 框架是什么 1.框架是用来提高开发效率的 2.封装了好了一些功能.我们需要使用这些功能时,调用即可.不需要再手动实现. 3.所以框架可以理解成是一个半成品的项目.只 ...

  3. Leetcode89. Gray Code格雷编码

    给定一个代表编码总位数的非负整数 n,打印其格雷编码序列.格雷编码序列必须以 0 开头. 示例 1: 输入: 2 输出: [0,1,3,2] 解释: 00 - 0 01 - 1 11 - 3 10 - ...

  4. vim编辑器操作①

    Linux文本编辑器: 行编辑器:sed 全屏编辑器:nano,vi/vim 本文主要介绍说明vim编辑器的相关使用: 其有三种模式,即: 编辑模式(默认模式).插入模式(输入模式).末行模式(内置的 ...

  5. 02Redis入门指南笔记(基本数据类型)

    一:热身 获得符合规则的健名列表:keys  pattern pattern支持glob风格的通配符,具体规则如下表: Redis命令不区分大小写.keys命令需要遍历Redis中的所有健,当键的数量 ...

  6. Odoo 中的widget

    many2many_tags one2many_list selection progressbar selection statusbar handle monetary mail_thread s ...

  7. js校验文本框只能输入数字(包括小数)

    form表单 <form method="POST" action=""> <input type="text" id=& ...

  8. h5+css3+Jq

    1.侧边栏划出一个信息框 通常鼠标浮动侧边栏都会划出一个信息框,每个信息框距离侧边栏的距离是相等的,所以处理此问题的方法就是 量取信息框距离侧边栏的距离,信息框设置绝对定位,父元素设置相对定位之后,信 ...

  9. 公司-广告-WPP:WPP

    ylbtech-公司-广告-WPP:WPP WPP集团 (LSE:WPP) (NASDAQ:WPPGY),是世界上最大的传播集团,总部位于英国伦敦.WPP集团拥有 60 多个子公司,主要服务于本地.跨 ...

  10. WPF 利用HwndSource拦截Windows消息

    WPF提供了一个HwndSource可以使你更快的实现处理Windows消息. 通过HwndSource.FromHwnd得到的HwndSource可以添加(AddHook)移除(Remove)Hoo ...