2017-05-14 24 views
0

은 내가 mybatis 매퍼 프록시에서 sqlSession 인스턴스를 얻는 방법은 무엇입니까?

내가 SQLSESSION 인스턴스를 얻으려면 enter image description here

정보

아래에있어 mybatis mapper

public interface FooMapper { 
    @Select("select now()") 
    String getTime(); 
} 

때 디버그있다. 그래서 반사 방식을 사용하여 sqlSession을 얻으려고 노력했습니다.

Field hField = fooMapper.getClass().getDeclaredField("h"); 

    MapperProxy mapperProxy = (MapperProxy) hField.get(fooMapper); 

    Field sqlSessionField = mapperProxy.getClass().getDeclaredField("sqlSession"); 
    SqlSession sqlSession = (SqlSession) sqlSessionField.get(mapperProxy); 

하지만 실제로 나는

java.lang.NoSuch FieldException: h 
    at java.lang.Class.getDeclaredField(Class.java:2070) 

오류

아래에 있어요 그래서 반사 형태 또는 다른 방법으로 (반사가 불가능한 경우)에 의해 fooMapper에 SQLSESSION 인스턴스를 얻는 방법?

답변

0

이 작동 :

((MapperProxy)((Proxy)fooMapper).h).sqlSession 

MapperProxyJava.lang.reflect

에서

Proxyorg.apache.ibatis.binding에서