开发者社区> 问答> 正文

Spring mvc 3.0 配置403.10 禁止访问:配置无效 

初学Spring mvc,配置如下:、
web.xml

applicationContext.xml 配置

测试类:

启动报错:

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 21 in XML document from class path resource [META-INF/applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'context:component-scan'.     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)     at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)     at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)     at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)     at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:124)     at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:93)     at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)     at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:465)     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:395)     at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:443)     at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:459)     at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:340)     at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:307)     at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)     at javax.servlet.GenericServlet.init(GenericServlet.java:212)     at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)     at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993)     at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4421)     at org.apache.catalina.core.StandardContext.start(StandardContext.java:4734)     at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)     at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)     at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)     at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)     at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)     at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)     at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)     at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)     at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)     at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)     at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)     at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)     at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)     at org.apache.catalina.core.StandardService.start(StandardService.java:525)     at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)     at org.apache.catalina.startup.Catalina.start(Catalina.java:595)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)     at java.lang.reflect.Method.invoke(Method.java:597)     at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)     at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414) Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'context:component-scan'.     at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)     at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)     at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)     at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)     at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(XMLSchemaValidator.java:410)     at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(XMLSchemaValidator.java:3165)     at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1898)     at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.emptyElement(XMLSchemaValidator.java:705)     at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:377)     at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2747)     at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)     at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)     at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)     at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)     at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)     at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)     at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:225)     at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)     at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75)     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388)     ... 42 more 2013-1-18 15:14:33 org.apache.catalina.core.StandardContext loadOnStartup 严重: Servlet /Spring001 threw load() exception
报错是在这:
<context:component-scan  base-package="net.hsf"/>
我的测试类包名--net.hsf.controller是以net.hsf命名的啊。不明白了,求解释... 3q

webxml  少了 applicationContext的监听吧######

引用来自“付乐”的答案

webxml  少了 applicationContext的监听吧
额、加上也不行- 报错: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 21 in XML document from ServletContext resource [/WEB-INF/applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'context:component-scan'. 21行,还是那个问题--> 蓝色部分。郁闷了...
######
<context:annotation-config />  这个注解支持加上了么
######介个######

引用来自“付乐”的答案

<context:annotation-config />  这个注解支持加上了么
你看下 配置截图,还需加什么支持;; 3q.

展开
收起
kun坤 2020-05-27 20:03:58 580 0
1 条回答
写回答
取消 提交回答
  • ######把配置文件换个位置,一般不妨到META-INF下###### 是否要通过代理才能访问网络? spring-tx jar 包版本是 3.0版还是以后的版本?
    2020-05-28 16:15:49
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Java Spring Boot开发实战系列课程【第7讲】:Spring Boot 2.0安全机制与MVC身份验证实战(Java面试题) 立即下载
Spring Cloud 微服务核心组件集 mica 的设计思路 立即下载
workshop专场-微服务专场-开发者动手实践营-微服务-Spring Cloud Alibaba 微服务全家桶体验 立即下载

相关实验场景

更多