2 yt1037921169 yt1037921169 于 2016.03.10 17:26 提问

spring+ibatis 事务错误

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'studentdao' defined in URL [file:/E:/资料/apache-tomcat-6.0.29/webapps/firstibatis/WEB-INF/classes/spring/applicationContext-jdbc.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'driverClassName' of bean class [dao.impl.StudentDaoImpl]: Bean property 'driverClassName' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1427)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1132)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:607)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1041)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:964)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:502)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
at org.apache.catalina.core.StandardService.start(StandardService.java:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)

xml配置文件如下:


 <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  
        <property name="dataSource" ref="dataSource"/>  
        </bean>  

       <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">  

        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>  

        <property name="url" value="jdbc:mysql://127.0.0.1/student"/>  

        <property name="username" value="root"/>  

        <property name="password" value="root"/>  

    </bean>  

<!--配置哪些方法,什么情况下需要回滚-->


tx:attributes

<!--当代理的service层中的方法抛出异常的时候才回滚,必须加rollback-for参数-->





<!--除了上面标识的方法,其他方法全是只读方法 -->


/tx:attributes

/tx:advice

<!-- 配置哪些类的方法需要进行事务管理 -->







/aop:config

<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">  
       <property name="configLocation"><value>classpath:config/jdbc/sqlMapConfig.xml</value></property>  
 </bean>  
<bean id="studentdao" class="dao.impl.StudentDaoImpl">
    <property name="sqlMapClient" ref="sqlMapClient"></property>
</bean>
<bean id="studentmanager" class="manager.impl.StudentManagerImpl">
    <property name="studentdao" ref="studentdao"></property>
</bean>




    studentdaoimpl

      public class StudentDaoImpl   extends SqlMapClientDaoSupport implements StudentDao{

@Override
public List<Student> getAllStudent() {
    // TODO Auto-generated method stub
    return null;
}

@Override
public Student getStudentById(String id) {
    // TODO Auto-generated method stub
    return null;
}

@Override
public List<Object> select(String name) throws Exception {
    // TODO Auto-generated method stub
    return null;
}

@Override
public List<Student> selects(Map map) throws Exception {
    // TODO Auto-generated method stub
    return null;
}

@Override
public void tianjia(Map map) throws Exception {
    // TODO Auto-generated method stub

}

@Override
public void update(Map map) throws Exception {
    // TODO Auto-generated method stub

}

}

2个回答

xinanwumeng
xinanwumeng   2016.03.10 17:55

StudentDaoImpl 里面没有sqlMapClient 的定义

yt1037921169
yt1037921169 这不是已经注入进去了吗? 继承 的是SqlMapClientDaoSupport 这个类 错误是 Bean property 'driverClassName' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
接近 2 年之前 回复
yt1037921169
yt1037921169   2016.03.10 18:13

你好!


这不是已经注入进去了吗?
继承 的是SqlMapClientDaoSupport 这个类

    Bean property 'driverClassName' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!