Summary of Solutions to Eleven Common Anomalies in Spring Framework
- 2021-07-03 00:12:06
- OfStack
In the programmer's career, the SSH3 framework should be mentioned most. As the first big framework, Spring framework is often used.
However, in the process of use, encountered a lot of common anomalies, I summarize 1 here, we encourage each other.
1. Unable to find configuration file exception
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
Explanation: This means that there is no xml whose configuration file is controller, and the name of the configuration file can be modified under 1.
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:com/herman/ss/config/testAjax.xml</param-value>
</init-param>
2. The namespace configured in xml cannot find the corresponding exception for Schema
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 'util:list'.
xmlns:util="http://www.springframework.org/schema/util" Remove, because schema Does not exist in util Naming
3. Exception not found for jackson. jar
StandardWrapper.Throwable
java.lang.NoClassDefFoundError: org/codehaus/jackson/JsonProcessingException
If jar package is missing jackson, import jackson-all-1. 9.5. jar
4. bean is not the only exception
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.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:313)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:985)
at com.herman.ss.test.Test0.test1(Test0.java:35)
at com.herman.ss.test.Test0.main(Test0.java:111)
The exception is that we are still using ctx. getBean (Person. class) after a class is configured with more than one bean; Method, that is, according to the class mapping of bean, to get the bean object. The bean object returned at this time is not only 1, but has multiple bean objects. The solution is to get the bean object according to the id of bean.
5. Log jar package missing
java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
The problem is that the jar package file that spring depends on is missing from the project. Solution: Add commons-logging-1. 1.3. jar.
6. bean exception not found
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'filter2' is defined
The problem is that bean whose name is filter2 cannot be found in the project. To put it bluntly, you can't find bean whose id is filter2 in applicationContext. xml, so you can configure it under 1.
7. spring-webmvc-4. 0.6. RELEASE. jar package missing
Serious : 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.DispatcherServlet
java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
Solution: Add mvc package of spring to the project. If my version of spring is 4.0. 6, just add spring-webmvc-4. 0.6. RELEASE. jar.
8. spring-aop-4. 0.6. RELEASE. jar package missing
java.lang.NoClassDefFoundError: org/springframework/aop/TargetSource
java.lang.ClassNotFoundException: org.springframework.aop.TargetSource
Solution: Add the aop frame package of spring to the project. If my version of spring is 4.0. 6, just add spring-aop-4. 0.6. RELEASE. jar.
9. spring-expression-4. 0.6. RELEASE. jar package missing
java.lang.NoClassDefFoundError: org/springframework/expression/ExpressionParser
java.lang.ClassNotFoundException: org.springframework.expression.ExpressionParser
Solution: Add expression package of spring to the project. If my version of spring is 4.0. 6, just add spring-expression-4. 0.6. RELEASE. jar.
10. The name name or id or alias alias already exists for bean
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:com/herman/ss/config/testAjax.xml</param-value>
</init-param>
0
Solution: Change the duplicate name to a new name.
101. The bean auto-load could not find a corresponding bean problem
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:com/herman/ss/config/testAjax.xml</param-value>
</init-param>
1
Solution: In the configuration file < beans > Add default-autowire= "byName" default-lazy-init= "true" under the root node or < context:component-scan base-package="com.xxx.dao.*" > < /context:component-scan > Match with * under the package
Summarize