exception集合

1、java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for

在写junt单元测试的时候,老是报这个错误,在度娘后发现是mapper文件的错误,namespace地址写错了。如<mapper namespace="com.sitech.mapper.StudentMapper">

看网友们的结论里,有下述原因可能导致这个错误:

1、namespace写错。

2、mapper文件中的id和dao文件中方法名不一致。

3、文件配置出错。

4、今天报这个错误,是xml里select语句的id和mapper文件里面的方法名不一样,实在是2死了。。。20131101

 

 

2、System.Data.SqlClient.SqlError: 备份集中的数据库备份与现有的 'XXX' 数据库不同。

用的是sqlserver2008版本,报这个错误的时候,可以直接还原数据库,而且不用新建数据库再还原。

也有别的情况,如:使用的版本不对,备份文件版本高,数据库系统版本低.这种情况则无法还原.

 

3、org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory

在spring+ibatis框架里采用了连接池,连接的数据库都是我自己的电脑里面的mysqlDB,使用127.0.0.1的时候是没有问题的,换成IP地址以后就报错org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory
(Io 异常: The Network Adapter could not establish the connection),百度了下可能是:

1、网络问题:ping 服务器IP是否通畅。

2、防火墙:如果机器上安装有放火墙,可能是服务器端口号屏蔽而造成的。关闭防火墙后,尝试重新连接。

检查网络,没有问题;在把防火墙关闭以后,发现正常部署了。当然,要把项目和tomcat都clean一下,要不可能会报乱七八糟的错。

 

 

4、org.springframework.beans.factory.BeanCreationException和autowire异常

报错信息如下:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'companyServiceTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests.setDataSource(javax.sql.DataSource); nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [javax.sql.DataSource] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests.setDataSource(javax.sql.DataSource); nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [javax.sql.DataSource] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [javax.sql.DataSource] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}

报错的究极原因还是没有找到serviceImpl对应的类,找了很久,发现可能是以下2个原因:

1、jar包错了;

2、applicationContext.xml中文件头和基本包没写对,正确文件如下:

  1. <?xmlversion="1.0"encoding="utf-8"?> 
  2. <beans xmlns="http://www.springframework.org/schema/beans" 
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:tx="http://www.springframework.org/schema/tx" 
  4.     xmlns:aop="http://www.springframework.org/schema/aop"xmlns:context="http://www.springframework.org/schema/context" 
  5.     xmlns:mvc="http://www.springframework.org/schema/mvc" 
  6.     xsi:schemaLocation="http://www.springframework.org/schema/beans     
  7.     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd     
  8.     http://www.springframework.org/schema/tx     
  9.     http://www.springframework.org/schema/tx/spring-tx-3.0.xsd    
  10.     http://www.springframework.org/schema/aop 
  11.     http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
  12.     http://www.springframework.org/schema/context    
  13.     http://www.springframework.org/schema/context/spring-context-3.0.xsd    
  14.     http://www.springframework.org/schema/mvc    
  15.     http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> 
  16.  
  17.     <context:component-scanbase-package="com.tc.jms"/> 
<?xml version="1.0" encoding="utf-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/beans    
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd    
    http://www.springframework.org/schema/tx    
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd   
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    http://www.springframework.org/schema/context   
    http://www.springframework.org/schema/context/spring-context-3.0.xsd   
    http://www.springframework.org/schema/mvc   
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

	<context:component-scan base-package="com.tc.jms" />


当时在网上百度到了其他原因,先收着:http://zhongzhihua.iteye.com/blog/613305

像上面的情况是BrandDao没有注入,


a、你的BrandServiceImpl必须以@Service或@Component注解才行。

b、自动写入的时候把接口写成实现类了
@Autowired
private BrandServiceImpl      brandServiceImpl;
应该是
@Autowired
private BrandService    brandService ;

c、在BrandDao 类上加上@Repository注解

 

4、Eclipse “cannot be resolved to a type” error

(1)jdk不匹配(或不存在)

    项目指定的jdk为“jdk1.6.0_18”,而当前eclipse使用的是“jdk1.6.0_22”。需要在BuildPath | Libraries,中做简单调整。
(2)jar包缺失或冲突

    当找不到“XX”所在的jar包时,会报这个错。解决只需要找到(ctrl+点击,可能能看到jar包名称)对应jar包导入项目即可。

    另外,出现相同的XX时也会报此错。可能需要调包、解包、选删。 
(3)eclipse查找项目类型策略所致

    eclipse下,上述两条都对比过了,没有任何问题,可偏偏还报这错。这时,需要操作一下 Project | Clean... ,问题即可解决。原因是,机制所致。因为某些特殊原因,eclipse没能自动编译源代码到build/classes(或其他classes目录),导致类型查找不到。

Based on the comments here, I started checking how I could make sure that my Ant build

wouldn’t interfere with my Eclipse build.

I found an option in Eclipse that clears up the problem (and is possibly more efficient than

changing the 2 build system’s output folders).

Windows–>Preferences–>Java–>Compiler–>Building–>Output folder–>

”Rebuild class files modified by others”. This exists in Eclipse 3.5; I’m not sure about earlier versions.

Checking this seems to have fixed my problems.

 

5、Unable to translate SQLException with SQL state '42703', error code '0, will now try the fallback tr

这个错误指出resultMap里有问题。说错误发生在设置某一个属性的时候,但是没有具体说明是一个怎么样的错误<NULL错误>。由于对于iBatis了解还不是很深,所以一时不知如何事好。只有在resultMap里面作文章,把里面的<result>注释掉一些,哈哈,程序居然正常跑起来了。看来我快要找到错误了,接着继续排除其它的<result>,终于让我找到出错的一行<result>了:<result property="deleted" column="deleted"/>
  接下来得弄清楚是一个什么样的错误,怎么去修复它。查找数据库表,发现"deleted"这一列是nullable,并且没有为它设置默认值。所以表里面deleted这一列有许多都为NULL。我大概明白了,肯定是iBatis试图把从数据库读出来的NULL 值写入对象属性的时候出现异常。采取的补救措施就是:
<result property="deleted" column="deleted" nullValue="0"/>
对从数据库读出来的NULL值采用一个相应可转换为deleted类型的值来替换

 

6、No result defined for action and result input

http://wcf1987.iteye.com/blog/991021

这个错误就是说没有为返回的input定义,可是有时候我们不一定要这个鬼东西,然而在Action中出错的话,默认就返回了这个input了,这时,我们在struts的<result>中定义的话,就出现No result defined for action and result input的错误了。
引起这个错误的原因是很多的,路径错误也是其中的一种,我这里的问题是,我的页面上的类型和我定义的属性的类型不一致,我的属性是int型的,但是在页面上输出的时候加了一个逗号,用了分割千位的,结果就出现了这个问题了。

这个问题好像在strtus2.1以上版本才出现, 这个问题的上面的解决方案已经把原因说的差不多了,在实际应用中,我估计大部分情况应该都是在action里面定义了int或者别的什么类型的变量,然后指望struts的自动填装把post来的数据转换,这时容易出现转换失败,从而导致了这个错误,所以查这个错误,可以利用ff的httpfox来查看实际post的参数是什么,然后和action中对应的属性对比,看那个会出现转换错误。

    淡然另一种就是上面说的在所有的set 中加入断点,总能看到是哪个方法执行失败的。

    另外还有种就是页面提交了同一个名字的参数多个,比如

写道
username 123
username 123
permissions 123
info 31234

页面冲提交了了两个username ,而我的后台却只写了一个String username,这样同样会出错,这个是利用httpfox看的,

    其实最好的是action中的和post相对应属性都设置成为String类型,省事,也不会再出现这个错误了,然后在execute中执行转换。这样也方便差错

 

 7、mybatisGenerator 代码自动生成报错 Result Maps collection already contains value for BaseResultMap

我在运行时没有把之前已经生成的PetMapper.xml删除掉,再次生成代码时,又附加了上去!所以在运行代码生成之前,要把以前已经生成的xml文件清掉,以妨出错。

 

8、The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /opt/jdk1.6.0_13/jre/lib/i386/server:/opt/jdk1.6.0_13/jre/lib/i386:/opt/jdk1.6.0_13/jre/../lib/i386:/usr/java/packages/lib/i386:/lib:/usr/lib

这个是在linux下启动tomcat时报错,解决方法如下:

tomcat bin目录中有 tomcat-native.tar.gz解压
[root@localhost bin]# cd /opt/tomcat5.5/bin
[root@localhost bin]# tar zxf tomcat-native.tar.gz
[root@localhost bin]# cd bin/tomcat-native-1.1.16-src/jni/native/
[root@localhost bin]# ./configure --with-apr=/usr/bin/apr-1-config --with-java-home=/usr/java/jdk1.5/ 
[root@localhost bin]# make
[root@localhost bin]# ls .libs  查看相应的文件是否生成
[root@localhost bin]# make install   (要记得权限  sudo )
[root@localhost bin]# ls /usr/local/apr/lib   查看是否成功
[root@localhost bin]# vi bin/catalina.sh
CATALINA_OPTS="-Djava.library.path=/usr/local/apr/lib"   加到这个文件中

http://www.f5ha.com/2011/0301/2OMDAwMDAwMDQ2OQ.html

 

9、Failed to bind NettyServer on /xxx.xxx.xxx.xxx:xxxxx, cause: Failed to bind to:\

出现这个错误的原因是因为dubbo已经启动,而又再次启动。


10、严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

严重: Error configuring application listener of class org.springframework.web.util.IntrospectorCleanupListener
java.lang.ClassNotFoundException: org.springframework.web.util.IntrospectorCleanupListener

在这里找到了答案:http://stackoverflow.com/questions/6210757/java-lang-classnotfoundexception-org-springframework-web-context-contextloaderl

 解决步骤:

1) Open the project's properties (e.g., right-click on the project's name in the project explorer and select "Properties")
2) select "Deployment Assembly"
3) Click the "Add..." button on the right margin
4) Select "Java Build Path Entries" from the menu of Directive Type and click "Next"
5) Select "Maven Dependencies" from the Java Build Path Entries menu and click "Finish".

You should see "Maven Dependencies" added to the Web Deployment Assembly definition.


11、今天改一个maven工程的properties之后,整个项目都报红叉了,也不清楚是什么情况,重新编译也不行,于是乎,要把整个项目删了,重新导入eclipse。注意项目所在地址要删除.setting文件夹、.classpath、.project文件。因为maven会自动更加pom文件来生成项目。


12、could not read json:这个错是在转化json数据的时候出现的,找了很久都没有找出来是哪里的问题,后来发现是我对应的bean文件里面有个isChecked属性的get、set方法出错了,编译器自动生成getter、setter方法的时候,像这种以is开头的字段很容易出错。


13、IE8下在form中直接submit时,会提交2次请求;后来将提交方式改为js提交后就好了。


14、launch configuration references closed project

参考http://blog.csdn.net/youthon/article/details/17006099

quote:最近总是在关闭一个工程时看到myeclipse里报这个错,Launch configuration XX类 references closed project XX

可XX类已经被删除了,后来发现是因为我之前用这个类的Main方法调试过,把调试列表里的对应项去掉就可以了

注意需要在该工程打开时才能看到,在myeclipse的工具栏里的debug的debug configurations界面里或者在工程属性的Run/debug Settings里都可以删除


其实,我遇到的情况是在debug项目的时候,会弹出如下提示,后来发现我确实无意中加了一个相同的debug命令。


15、java.lang.ArithmeticException: Non-terminating decimal expansion

http://wodexinlihua1.blog.163.com/blog/static/12396810820125611617125/

金额的数据类型是BigDecimal
通过BigDecimal的divide方法进行除法时当不整除,出现无限循环小数时,就会抛异常的,异常如下:java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result. at java.math.BigDecimal.divide(Unknown Source)

应用场景:一批中供客户的单价是1000元/年,如果按月计算的话1000/12=83.3333333333....

解决之道:就是给divide设置精确的小数点divide(xxxxx,2, BigDecimal.ROUND_HALF_EVEN)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值