org.apache.ibatis.ognl.MethodFailedException: Method "size" failed for object
2017-03-01 09:41
3067 查看
1 问题描述
mybatis3.2.x版本,做压力测试,并发200用户,出现了如下异常.
org.apache.ibatis.builder.BuilderException: Error evaluating expression 'size() > 0'. Cause: org.apache.ibatis.ognl.MethodFailedException: Method "size" failed for object [one, two] [java.lang.IllegalAccessException: Class org.apache.ibatis.ognl.OgnlRuntime can not access a member of class java.util.Collections$UnmodifiableCollection with modifiers "public"]
at org.apache.ibatis.scripting.xmltags.OgnlCache.getValue(OgnlCache.java:47)
at org.apache.ibatis.scripting.xmltags.ExpressionEvaluator.evaluateBoolean(ExpressionEvaluator.java:29)
at OgnlConcurrentTest$1.run(OgnlConcurrentTest.java:51)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.ibatis.ognl.MethodFailedException: Method "size" failed for object [one, two] [java.lang.IllegalAccessException: Class org.apache.ibatis.ognl.OgnlRuntime can not access a member of class java.util.Collections$UnmodifiableCollection with modifiers "public"]
at org.apache.ibatis.ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:837)
at org.apache.ibatis.ognl.ObjectMethodAccessor.callMethod(ObjectMethodAccessor.java:61)
at org.apache.ibatis.ognl.OgnlRuntime.callMethod(OgnlRuntime.java:860)
at org.apache.ibatis.ognl.ASTMethod.getValueBody(ASTMethod.java:73)
at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170) 2 解决方案
在网上搜了一桶,找到原因是mybatis3.2.x版本引用ognl的版本为2.6.9,出问题的地方代码如下。
因为mybatis-spring1.2.x引用的mybatis版本还是mybatis3.2.x,故需要升级。
public static Object invokeMethod(Object target, Method method, Object[] argsArray)
throws InvocationTargetException, IllegalAccessException
{
boolean wasAccessible = true;
if (securityManager != null) {
try {
securityManager.checkPermission(getPermission(method));
} catch (SecurityException ex) {
throw new IllegalAccessException("Method [" + method + "] cannot be accessed.");
}
}
if (((!Modifier.isPublic(method.getModifiers())) || (!Modifier.isPublic(method.getDeclaringClass().getModifiers()))) &&
(!(wasAccessible = method.isAccessible()))) {
method.setAccessible(true);
}
Object result = method.invoke(target, argsArray);
if (!wasAccessible) {
method.setAccessible(false);
}
return result;
}参考资料
MyBatis 3.2.x版本在并发情况下可能出现的bug及解决办法
mybatis3.2.x版本,做压力测试,并发200用户,出现了如下异常.
org.apache.ibatis.builder.BuilderException: Error evaluating expression 'size() > 0'. Cause: org.apache.ibatis.ognl.MethodFailedException: Method "size" failed for object [one, two] [java.lang.IllegalAccessException: Class org.apache.ibatis.ognl.OgnlRuntime can not access a member of class java.util.Collections$UnmodifiableCollection with modifiers "public"]
at org.apache.ibatis.scripting.xmltags.OgnlCache.getValue(OgnlCache.java:47)
at org.apache.ibatis.scripting.xmltags.ExpressionEvaluator.evaluateBoolean(ExpressionEvaluator.java:29)
at OgnlConcurrentTest$1.run(OgnlConcurrentTest.java:51)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.ibatis.ognl.MethodFailedException: Method "size" failed for object [one, two] [java.lang.IllegalAccessException: Class org.apache.ibatis.ognl.OgnlRuntime can not access a member of class java.util.Collections$UnmodifiableCollection with modifiers "public"]
at org.apache.ibatis.ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:837)
at org.apache.ibatis.ognl.ObjectMethodAccessor.callMethod(ObjectMethodAccessor.java:61)
at org.apache.ibatis.ognl.OgnlRuntime.callMethod(OgnlRuntime.java:860)
at org.apache.ibatis.ognl.ASTMethod.getValueBody(ASTMethod.java:73)
at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170) 2 解决方案
在网上搜了一桶,找到原因是mybatis3.2.x版本引用ognl的版本为2.6.9,出问题的地方代码如下。
Modifier.isPublic存在问题,好在ognl2.7版本已经修复,故将mybatis版本升级到mybatis3.3.x以上,同时升级mybatis-spring到1.3.x以上即可。
因为mybatis-spring1.2.x引用的mybatis版本还是mybatis3.2.x,故需要升级。
public static Object invokeMethod(Object target, Method method, Object[] argsArray)
throws InvocationTargetException, IllegalAccessException
{
boolean wasAccessible = true;
if (securityManager != null) {
try {
securityManager.checkPermission(getPermission(method));
} catch (SecurityException ex) {
throw new IllegalAccessException("Method [" + method + "] cannot be accessed.");
}
}
if (((!Modifier.isPublic(method.getModifiers())) || (!Modifier.isPublic(method.getDeclaringClass().getModifiers()))) &&
(!(wasAccessible = method.isAccessible()))) {
method.setAccessible(true);
}
Object result = method.invoke(target, argsArray);
if (!wasAccessible) {
method.setAccessible(false);
}
return result;
}参考资料
MyBatis 3.2.x版本在并发情况下可能出现的bug及解决办法
相关文章推荐
- org.apache.ibatis.ognl.MethodFailedException: Method "size" failed for object
- ognl.MethodFailedException: Method "setId" failed for object Itemer/org.springframework.orm.hibernat
- ognl.MethodFailedException: Method "setXX" failed for object
- ognl.MethodFailedException: Method "setRemainig" failed for object
- 解决ognl.MethodFailedException: Method "list" failed for object com.szy.ResourceAction的问题
- 进行修改时,发现记录不完整及ognl.MethodFailedException: Method "delete" failed for object cn.chenbiao.house.web.ac
- ognl.MethodFailedException: Method "setDate" failed for object解决
- ognl.MethodFailedException: Method "setEndtime" failed for object com.piptrade.action.tradetools.eCa
- 图片上传出现错误提示ognl.MethodFailedException: Method "setUpload" failed for object
- Caused by: org.apache.ibatis.ognl.OgnlException: source is null for getProperty(null, "list")
- Invocation of init method failed; nested exception is org.apache.ibatis.binding.BindingException: In
- Exception in thread "main" org.apache.ibatis.binding.BindingException: Mapper method 'com.demo.DAO.B
- org.apache.ibatis.ognl.OgnlException: source is null for getProperty(null, "mil_id")
- root cause org.apache.ibatis.ognl.OgnlException: source is null for getProperty(null, "XXX")
- Caused by: org.apache.ibatis.ognl.OgnlException: source is null for getProperty(null, "id")
- org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'id' in 'cla
- ognl.MethodFailedException: Method "setPic" failed for object com.employment.action.NewsAction@aac66
- ognl.MethodFailedException: Method "setManager" failed for object com.zhym.action.ItemAddAction@3e2a
- mllib:Exception in thread "main" org.apache.spark.SparkException: Input validation failed.
- org.apache.jasper.JasperException: /index.jsp (line: 24, column: 26) attribute for %>" is not proper