【问题标题】:Invalid property 'driverClass' of bean class [org.springframework.jdbc.datasource.DriverManagerDataSource] for org.postgresql.Driverorg.postgresql.Driver 的 bean 类 [org.springframework.jdbc.datasource.DriverManagerDataSource] 的属性“driverClass”无效
【发布时间】:2015-10-21 19:54:27
【问题描述】:

我正在尝试将 JPA SpringData Framework 与 Hibernate 和 PSQL 一起使用,但遇到了这个错误 stackoverflow 要我在这里写 smt stackoverflow 要我在这里写 smt stackoverflow 要我在这里写 smt stackoverflow 要我在这里写 smt stackoverflow要我在这里写smt

 java.lang.IllegalStateException: Failed to load ApplicationContext
    at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:94)

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [META-INF/ApplicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'driverClass' of bean class [org.springframework.jdbc.datasource.DriverManagerDataSource]: Bean property 'driverClass' 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:1514)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1222)

Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'driverClass' of bean class [org.springframework.jdbc.datasource.DriverManagerDataSource]: Bean property 'driverClass' 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.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1076)
    at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:927)
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:95)
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1510)
    ... 44 more

这是我的 ApplicationContext.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:jdbc="http://www.springframework.org/schema/jdbc"
       xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://www.springframework.org/schema/jdbc
                           http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
                           http://www.springframework.org/schema/data/jpa
                           http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
    <!-- database -->
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClass" value="org.postgresql.Driver"></property>
        <property name="jdbcUrl" value="jdbc:postgresql://localhost:5433/journey"></property>
        <property name="user" value="postgres"></property>
        <property name="password" value="canada"></property>
    </bean>
    <!-- entity Manager -->
    <bean id="entityManagerFactory"
          class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="persistenceUnitName" value="MAP"/>
    </bean>
    <!-- Transaction Manager -->
    <bean id="myTransactionManager"
          class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>
    <!-- JPA package -->
    <jpa:repositories base-package="home.map.events.dao"></jpa:repositories>

</beans>

如果有人有任何建议,请在帖子中评论 谢谢

【问题讨论】:

  • 发布您的配置详情

标签: java spring postgresql jpa postgresql-9.1


【解决方案1】:

它声称org.springframework.jdbc.datasource.DriverManagerDataSource 没有名为driverClass 的属性,因为DriverManagerDataSource 只有driverClassName 的属性。

查看documentation

所以你应该把这行改成:

        <property name="driverClassName" value="org.postgresql.Driver"></property>

【讨论】:

  • 好吧,现在它说'org.springframework.beans.NotWritablePropertyException:bean类[org.springframework.orm.jpa.LocalEntityManagerFactoryBean]的无效属性'dataSource':Bean属性'dataSource'不可写或具有无效的 setter 方法。 setter的参数类型和getter的返回类型是否匹配?'
  • 没关系,现在已经解决了,我改成'' 谢谢
猜你喜欢
  • 2013-12-12
  • 1970-01-01
  • 2018-10-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-26
  • 1970-01-01
  • 2019-12-01
相关资源
最近更新 更多