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

时间:2018-04-09 04:39:24

标签: java mysql spring jdbc mybatis

我试图整合spring和mybatis。

JDK:1.8

运行我的测试:

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

且错误the full stacktrace

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

弹簧配置文件:

    <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’

关于权威的java.lang.IllegalAccessError? 我不知道

2 个答案:

答案 0 :(得分:1)

我将commons-dbcp-1.2.1.jar更改为commons-dbcp-1.4.jar,现在已经可以了!

答案 1 :(得分:0)

是的,您的解决方案是正确的。 如果看一下DelegatingPreparedStatement.isClosed()javadoc,您会看到此方法受到保护,因此您一方尝试调用此方法的任何尝试都会以IllegalAccessException结尾,因为您没有执行此操作的权限。该库的较新版本已将此方法公开发布