栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

2021-10-20 spring-mvc.xml和application-context.xml在web.xml中的配置问题

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

2021-10-20 spring-mvc.xml和application-context.xml在web.xml中的配置问题

错误信息:

ERROR[localhost-startStop-1] - Context initialization failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.itheima.core.service.UserService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

提示信息:执行上下文失败,没有相应的bean可以用 分析:bean没有扫描到,此代码的问题则为,在web.xml文件中配置的 application-context.xml 所用的监听器的架包错误
	
    
    	contextConfigLocation
    	classpath:applicationContext.xml
    
    
    	
    	
    		 org.springframework.web.context.ContextCleanupListener
    		
    		     org.springframework.web.context.ContextLoaderListener
    	
    
关于 application-context.xml 和 spring-mvc.xml 配置的理解

1、application-context.xml是全局的,应用于多个serverlet,配合listener一起使用,web.xml中配置如下: 

    
        org.springframework.web.context.ContextLoaderListener
    
    
        contextConfigLocation
        classpath:applicationContext.xml
    

2、spring-mvc.xml 是spring mvc的配置,web.xml中配置如下: 

    	
   		
   		crm
   		
   			
   			org.springframework.web.servlet.DispatcherServlet
   		
   		
   		
   			contextConfigLocation
   			
   			classpath:springmvc-config.xml
   		
   		
   		1
   	

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/337226.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号