簡體   English   中英

使用spring3的mybatis配置

[英]mybatis configuration with spring3

我正在嘗試使用Spring 3配置mybatis。在構建項目時出現以下錯誤。

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?

我的spring-servel.xml是

<?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文件。 我添加了

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

如果您需要任何進一步的說明,請告訴我

問題與myBatis無關。

org.apache.commons.dbcp.BasicDataSource沒有任何“驅動程序”屬性。 我認為您應該改為使用driverClassName

請參閱doc

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM