1

i tried to make integration of spring and mybatis.

jdk:1.8

run my test:

    @Test
    public void testFindUserById() throws Exception{
        UserMapper userMapper=(UserMapper)applicationContext.getBean("userMapper");
        User user=userMapper.findUserById(1);
        System.out.println(user);
    }

and error:the full stacktrace

java.lang.IllegalAccessError: org.apache.commons.dbcp.DelegatingPreparedStatement.isClosed()Z

The spring configuration file:

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:3306/custom?useSSL=false" />
        <property name="username" value="root" />
        <property name="password" value="qqwe5631652" />
        <property name="maxIdle" value="5" />
    </bean>

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="configLocation" value="classpath:SqlMapConfig.xml" />

    </bean>
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="mapper" />
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
        </bean>

    <bean id="userDao" class="dao.UserDaoImpl">
        <property name="sqlSessionFactory" ref="sqlSessionFactory" />

    </bean>
</beans>

file's structure all of ‘.jar’

It 's java.lang.IllegalAccessError about authority? i have no idea

Peter
  • 61
  • 6
  • Could you post the full stacktrace? – lakshman Apr 09 '18 at 04:43
  • @lakshman,it 's too long and i had uploaded the picture about it – Peter Apr 09 '18 at 05:00
  • The reason for this error is compiled classes and run time classes are incompatibly different. please check that. Refer https://stackoverflow.com/questions/7076414/java-lang-illegalaccesserror-tried-to-access-method for more details about this error. – lakshman Apr 09 '18 at 06:06

2 Answers2

3

i change commons-dbcp-1.2.1.jar into commons-dbcp-1.4.jar ,and it 's ok now!

Peter
  • 61
  • 6
0

Yeah, your solution was right. If you take a look to DelegatingPreparedStatement.isClosed() javadoc you can see that this method is protected so any attempt from your side to invoke this method will end up in an IllegalAccessException because you don't have permissions to do this. Newer versions of this library has turned this metod up public

Facepalmed
  • 751
  • 12
  • 14