0

I am trying to configure mybatis with spring 3. I am getting the following error while building my project.

Error creating bean with name 'datasource' defined in ServletContext resource [/WEB-       INF/spring-servlet.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'driver' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'driver' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

My spring-servel.xml is

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.1.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">


<!-- Enable annotation driven controllers, validation etc... -->
<mvc:annotation-driven />


<context:component-scan
    base-package="com.mycom.mycontroller.controller" />

<mvc:resources mapping="/resources/**" location="/resources/" />


<bean id="datasource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driver" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://localhost/mydatabase"/>
    <property name="username" value="root"/>
    <property name="password" value="root"/>
</bean>

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="com.mycom.mydatabase.db.mybatis.sqlmap" />
</bean> 

<bean id="viewResolver"
    class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass"
        value="org.springframework.web.servlet.view.JstlView" />
    <property name="prefix" value="/WEB-INF/jsp/" />
    <property name="suffix" value=".jsp" />
</bean>

Jar files. I have added are

commons-dbcp-1.4.jar
commons-pool-1.6.jar
mybatis-3.1.0.jar
mybatis-spring-1.1.1.jar
mysql-connector-java-5.1.18-bin.jar
org.springframework.transaction-3.1.1.RELEASE.jar
and other spring jars

Please let me know if you need anything for more clarification

Harry
  • 4,705
  • 17
  • 73
  • 101

1 Answers1

1

Problem has nothing to do with myBatis.

org.apache.commons.dbcp.BasicDataSource has not any "driver" property. I think you should user driverClassName instead.

See doc.

jddsantaella
  • 3,657
  • 1
  • 23
  • 39
  • I am going to do that it say I can't accept the answer so quick.I'll do it in 3 mins. Thanks a lot – Harry Aug 02 '12 at 10:55
  • Hi Jddsantaella, Need your help could you please look at my question whenever you have sometime at http://stackoverflow.com/questions/12643207/how-would-i-pass-parameter-and-check-it-in-mybatis-dynamic-query-creation . No one has answered it yet. – Harry Sep 29 '12 at 07:31