spring框架常见的10个问题
webapp是什么架构⼀、不到配置⽂件的异常
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource
[com/herman/ss/controller]; nested exception is java.io.FileNotFoundException: class path resource [com/herman/ss/controller] cannot be opened because it does not exist解释:这个的意思是说,没有配置⽂件为controller的xml,修改⼀下配置⽂件名字即可。
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:com/herman/ss/l</param-value>
</init-param>
⼆、在xml中配置的命名空间不到对应的Schema的异常nested exception l.sax.SAXParseExce
ption: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element
'util:list'.xmlns:util="/schema/util" 去掉,因为schema中不存在util命名
三、不到jackson.jar的异常StandardWrapper.Throwable
java.lang.NoClassDefFoundError: org/codehaus/jackson/JsonProcessingException
缺少jackson的jar包,导⼊jackson-all-1.9.5.jar即可
四、bean不是唯⼀的异常
org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [com.herman.ss.pojo.Person] is defined: expected single matching bean but found 7: person0,person1,person2,person3,person4,person5,person6 at
org.springframework.beans.factory.Bean(DefaultListableBeanFactory.java:313) at
t.Bean(AbstractApplicationContext.java:985) at
com.st1(Test0.java:35) at com.st.Test0.main(Test0.java:111)这个异常是说,⼀个类配置了多个bean之后,我们还在使⽤Bean(Person.class);⽅法,即根据bean的类映射去获取bean对象。这个时候返回的bean对象不是唯⼀的,有多个bean对象。解决⽅法,就是根据bean的id去获取bean对象。
五、缺少⽇志jar包
java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactoryCaused by: java.lang.ClassNotFoundException:
org.apachemons.logging.LogFactory这个问题是说,项⽬中缺少spring依赖的jar包⽂件。解决⽅案:加⼊commons-logging-1.1.3.jar即可。
六、不到bean异常
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'filter2' is defined这个问题是说,项⽬中不到name 为filter2的bean。说⽩了就是在l中不到id为
filter2的bean,配置⼀下即可。六、缺少spring-webmvc-
4.0.6.RELEASE.jar包
严重: Error loading WebappClassLoader context: /Struts_Spring_Project delegate: false repositories: /WEB-INF/classes/----------> Parent Classloader:org.apache.catalina.loader.StandardClassLoader@b33d0a
org.springframework.web.servlet.DispatcherServletjava.lang.ClassNotFoundException:
org.springframework.web.servlet.DispatcherServlet
解决⽅案:在项⽬中加⼊spring的mvc架包即可。如我的spring版本为4.0.6的,那么就把spring-webmvc-4.0.6.RELEASE.jar添加进去即可。
七、缺少spring-aop-4.0.6.RELEASE.jar包
java.lang.NoClassDefFoundError: org/springframework/aop/TargetSource
java.lang.ClassNotFoundException: org.springframework.aop.TargetSource解决⽅案:在项⽬中加⼊s
pring的aop架包即可。如我的spring 版本为4.0.6的,那么就把spring-aop-4.0.6.RELEASE.jar添加进去即可。
⼋、缺少spring-expression-4.0.6.RELEASE.jar包
java.lang.NoClassDefFoundError: org/springframework/expression/ExpressionParser
java.lang.ClassNotFoundException: pression.ExpressionParser
解决⽅案:在项⽬中加⼊spring的expression架包即可。如我的spring版本为4.0.6的,那么就把spring-expression-4.0.6.RELEASE.jar添加进去即可。
九、bean的名字name或者id或者别名alias已经存在
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Bean name 'a' is already used in this <beans> element
解决⽅法:把重复的名字改个名字即可。
⼗、bean的⾃动加载不到相对应的bean问题
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [biz.YycBiz] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations:
{@org.springframework.beans.factory.annotation.Autowired(required=true)}解决⽅法:在配置⽂件中的<beans>根节点下加default-autowire="byName" default-lazy-init="true"或者<context:component-scan base-package="dao.*"></context:component-scan>包下⾯⽤*匹配
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论