java常见错误

java.lang.ClassNotFoundException: filter.EncodingFilter
找不到类

Type mismatch: cannot convert from ClassPathXmlApplicationContext toApplicationContext:
不能转换类,原因:ApplicationContext包导入错误

org.springframework.beans.factory.NoSuchBeanDefinitionException: No
bean named ‘holloBean’ is defined at
org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:704)
bean不存在

org.springframework.beans.factory.BeanCreationException: Error
creating bean with name ‘emp’ defined in class path resource
[applicationContext.xml]: Instantiation of bean failed; nested
exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [com.chinasofti.pojo.Emp]: No default
constructor found; nested exception is
java.lang.NoSuchMethodException: com.chinasofti.pojo.Emp.()
没有默认构造方法

org.springframework.beans.factory.CannotLoadBeanClassException:
Cannot find class [com.chinasofti.pijo.Emp] for bean with name ‘emp’
defined in class path resource [applicationContext.xml]; nested
exception is java.lang.ClassNotFoundException:
com.chinasofti.pijo.Emp
类找不到

org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem: Bean name ‘emp’ is already used in this
element Offending resource: class path resource
[applicationContext.xml]
name emp已经存在

org.springframework.beans.factory.BeanCreationException: Error
creating bean with name ‘props’: Invocation of init method failed;
nested exception is java.io.FileNotFoundException: class path
resource [db.propties] cannot be opened because it does not exist
文件找不到,文件名或者路径名错误

java.sql.SQLException: Access denied for user ‘root’@‘localhost’
(using password: YES)
连接拒绝,密码错误

org.springframework.beans.factory.BeanDefinitionStoreException:
Unexpected exception parsing XML document from class path resource
[applicationContext.xml]; nested exception is
java.lang.NoClassDefFoundError: org/springframework/aop/TargetSource
== 类找不到异常,缺少jar包==

org.springframework.beans.factory.NoSuchBeanDefinitionException: No
bean named ‘exampleBean’ is defined 找不到bean ,
扫描包范围错误或者没有在类上面添加spring注解或bean名字写错误

java.lang.IllegalStateException: BeanFactory not initialized or
already closed - call ‘refresh’ before accessing beans via the ApplicationContext
没有正确用spring的api加载配置文件,容器没有正常启动 传入的配置文件名字或者路径错误

java.lang.IllegalStateException: Failed to load ApplicationContextat
org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)at
org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83) at
org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)at
org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)at
org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:228) at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:230) at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:249) at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at
org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)at
org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at
org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)at
org.junit.runners.ParentRunner.run(ParentRunner.java:363) at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:193)at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by:
org.springframework.beans.factory.BeanDefinitionStoreException:
IOException parsing XML document from class path resource
[day0525/applicationContext.xml]; nested exception is
java.io.FileNotFoundException: class path resource
[day0525/applicationContext.xml] cannot be opened because it does not exist
找不到配置文件,应该要从类路径下查找: classpath:applicationContext.xml

java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name ‘userService’ defined in class path
resource [applicationContext2.xml]: Instantiation of bean failed;
nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [com.chinasofti.service.UserService]: Specified class is an interface
接口,不能创建实例 ,配置bean错误

Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name ‘userService’ defined in class path
resource [applicationContext2.xml]: BeanPostProcessor before
instantiation of bean failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name
‘org.springframework.aop.aspectj.AspectJPointcutAdvisor#0’: Bean
instantiation via constructor failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate
[org.springframework.aop.aspectj.AspectJPointcutAdvisor]:
Constructor threw exception; nested exception is
java.lang.IllegalArgumentException: Pointcut is not well-formed:
expecting ‘name pattern’ at character position 34
execution(com…UserServiceImpl.(…)) ^
表达式错误

Assert.assertEquals(1, 2); java.lang.AssertionError: expected:<1> but was:<2>
断言错误,没有通过断言Assert测试 原因是预期1作为结果的,但是却是2这个结果

java.util.concurrent.ExecutionException:
org.apache.catalina.LifecycleException: Failed to start component
[StandardEngine[Catalina].StandardHost[localhost].StandardContext[/spring0601]]
at java.util.concurrent.FutureTask.report(Unknown Source) at
java.util.concurrent.FutureTask.get(Unknown Source) at
org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123) at
org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:799)at
org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at
org.apache.catalina.core.ContainerBaseS t a r t C h i l d . c a l l ( C o n t a i n e r B a s e . j a v a : 1559 ) a t o r g . a p a c h e . c a t a l i n a . c o r e . C o n t a i n e r B a s e StartChild.call(ContainerBase.java:1559) at org.apache.catalina.core.ContainerBaseStartChild.call(ContainerBase.java:1559)atorg.apache.catalina.core.ContainerBaseStartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(Unknown Source) at
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown
Source) at java.lang.Thread.run(Unknown Source)
启动tomcat就引起该异常,异常说明是容器启动失败。原因考虑web.xml的配置文件 中是否正确配置

org.apache.ibatis.exceptions.PersistenceException: ### Error
querying database. Cause:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have
an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near ’ FROMDEPT’ at line 1
The error may exist in com/chinasofti/bean/DeptMapper.xml
The error may involve defaultParameterMap
The error occurred while setting parameters SQL: SELECT * FROM DEPT
Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have
an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near ’ FROM DEPT’ at line 1
SELECT * FROM DEPT该语句发生错误,空格处输入法问题

java.lang.ExceptionInInitializerError at
mybatis0606.TestMyBatis.setup(TestMyBatis.java:18) at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at
java.lang.reflect.Method.invoke(Unknown Source) at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24) at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at
org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: org.apache.ibatis.exceptions.PersistenceException: ###
Error building SqlSession. ### The error may exist in
com/chinasofti/bean/DeptMapper.xml ### The error occurred while
processing mapper_resultMap[deptVo] ### Cause:
org.apache.ibatis.builder.BuilderException: Error parsing SQL
Mapper Configuration. Cause:
org.apache.ibatis.builder.BuilderException: Error parsing Mapper
XML. Cause: org.apache.ibatis.builder.BuilderException: Error
resolving class. Cause: org.apache.ibatis.type.TypeException: Could
not resolve type alias ‘Dept’. Cause:
java.lang.ClassNotFoundException: Cannot find class: Dept

org.apache.ibatis.binding.BindingException: Invalid bound statement
(not found): com.chinasofti.dao.DeptMapper.findByDept
绑定语句异常,找不到sql语句,原因SQL语句的ID与Mapper接口的方法名不一致

org.apache.ibatis.binding.BindingException: Type interface
com.chinasofti.dao.DeptMapper is not known to the MapperRegistry.
绑定异常,接口类型 com.chinasofti.dao.DeptMapper无法进行注册,原因接口类型名与
mapper映射配置文件中的namespace不一致

Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name ‘sqlSessionFactory’ defined in class
path resource [spring_db.xml]: Invocation of init method failed;
nested exception is org.springframework.core.NestedIOException:
Failed to parse mapping resource: ‘file
[D:\javawork\mybatis0607_2\build\classes\com\chinasofti\dao\DeptMapper.xml]’;
nested exception is org.apache.ibatis.builder.BuilderException:
Error parsing Mapper XML. Cause:
java.lang.IllegalArgumentException: Result Maps collection already
contains value for com.chinasofti.dao.DeptMapper.deptVo
MapperStatement对象重名,即id重名。原因考虑映射配置xml文件是否重复的加载

org.springframework.beans.factory.BeanDefinitionStoreException:
IOException parsing XML document from ServletContext resource
[/WEB-INF/springServlet-servlet.xml]; nested exception is
java.io.FileNotFoundException: Could not open ServletContext
resource [/WEB-INF/springServlet-servlet.xml]
原因:web.xml配置 初始化加载错误

Caused by: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.chinasofti.dao.DeptMapper.deptMap
自定义ResultMap中已经包含了有com.chinasofti.dao.DeptMapper.deptMap的ID 即id重名

Caused by: java.lang.IllegalArgumentException: Result Maps collection does not contain value for com.chinasofti.dao.DeptMapper.deptMap2
找不到自定义的ResultMap ,原因 ID引用错误

Caused by: java.lang.ClassNotFoundException: Cannot find class: deptMap
找不到类,原因,自定义ResultMap需要在语句对象中设置resultMap属性,而不是resultType属性

initializationError(org.junit.runner.manipulation.Filter)
这个是由于你在测试的时候没有加上@Test,别那么粗心,
这是小问题,这个问题还有个是因为版本,我在测试mybatis的时候,出现了这样一个问题,我当时用的是4.11的版本,改了版本后就没有这个问题了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值