解決 Mybatis報錯org.apache.ibatis.ognl.NoSuchPropertyException: XXXCriteria$Criterion.noValue


問題

這個noValue一定存在,但是報錯。
場景就是存在並發的情況下,尤其是在服務剛剛啟動的時候,就會發生這個異常。

但是很不幸,mybatis 3.4.1之前,用的 OGNL都是由這個問題。

分析

3.4.1 之前的版本的 OgnlRuntime,這里,第三個參數傳0,則永遠都是null。

public static final Object getMethodValue(OgnlContext context, Object target, String propertyName, boolean checkAccessAndExistence) throws OgnlException, IllegalAccessException, NoSuchMethodException, IntrospectionException {
        Object result = null;
        Method m = getGetMethod(context, target == null ? null : target.getClass(), propertyName);
        if (m == null) {
            m = getReadMethod(target == null ? null : target.getClass(), propertyName, 0);
        }

3.4.1 以及以后的版本:

 public static final Object getMethodValue(OgnlContext context, Object target, String propertyName, boolean checkAccessAndExistence) throws OgnlException, IllegalAccessException, NoSuchMethodException, IntrospectionException {
        Object result = null;
        Method m = getGetMethod(context, target == null ? null : target.getClass(), propertyName);
        if (m == null) {
            m = getReadMethod(target == null ? null : target.getClass(), propertyName, (Class[])null);
        }

顯然 getReadMethod 這個地方的實現已經完全發生改變。


getGetMethod 存在 並發問題,線程不安全。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM