我试图将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);
}
和错误:完整的堆栈跟踪
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>
文件的结构所有".jar">
这java.lang.IllegalAccessError
关于权威?我不知道
我把commons-dbcp-1.2.1.jar
改成commons-dbcp-1.4.jar
,现在没事了!
是的,你的解决方案是正确的。如果你看一下DelegatingPreparedStatement.isClosed(( javadoc,你可以看到这个方法是受保护的,所以任何调用这个方法的尝试都会以IllegalAccessException告终,因为你没有这样做的权限。此库的较新版本已将此 metod 公开