【问题标题】:Does spring.xml file requires a internet connection?spring.xml 文件是否需要互联网连接?
【发布时间】:2017-04-02 09:06:16
【问题描述】:

我目前正在研究 spring,我对这个框架非常陌生。我已经添加了所有需要的spring jar,并编写了以下spring-dispatcher-servlet.xml 文件。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
                    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd     
                    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">

    <context:component-scan base-package="com.quiz_mcq.controller, com.quiz_mcq.service, com.quiz_mcq.dao"/>  
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name="prefix" value="/" />
      <property name="suffix" value=".jsp" />
    </bean>

</beans>

我的代码在有互联网连接时工作正常,但在我没有连接到互联网时出现故障。并给出以下错误。

来自 ServletContext 资源 [/WEB-INF/spring->dispatcher-servlet.xml] 的 XML 文档中的第 12 行无效;嵌套异常是 org.xml.sax.SAXParseException;行号:12;列号:109; cvc-complex-type.2.4.c:匹配的通配符是严格的,但找不到元素'context:component-scan'的声明。

我在这里做错了什么?
任何人都可以告诉我解决方案需要做什么才能离线完成项目吗?

【问题讨论】:

标签: java xml spring spring-mvc


【解决方案1】:

对于 xsi 架构位置放置

xsi:schemaLocation= "http://www.springframework.org/schema/beans 类路径:org/springframework/beans/factory/xml/spring-beans-3.0.xsd http://www.springframework.org/schema/context 类路径:org/springframework/beans/factory/xml/spring-context-3.0.xsd"

在您的情况下,代码每次都需要检查 springframework.com

我提供的架构位置应该可以工作,因为 xsd 被打包在 spring jar 中

【讨论】:

  • 我在架构位置添加了您的代码,但它仍然给我同样的错误
猜你喜欢
  • 1970-01-01
  • 2021-01-13
  • 1970-01-01
  • 2021-09-21
  • 1970-01-01
  • 2015-09-28
  • 1970-01-01
  • 2013-11-03
  • 1970-01-01
相关资源
最近更新 更多