我收到以下錯誤獲取錯誤bean類[..]的屬性'packagesToScan'無效。 Bean屬性「packagesToScan」不可寫無效或者和setter方法
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'packagesToScan' of bean class[org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Bean property 'packagesToScan' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?\
我使用spring3.2。使用MAven添加依賴項。一切似乎都好。爲什麼我得到這個錯誤。下面是我的文件
<?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:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
....
<bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
<property name="packagesToScan" value="pk.training.basitMahmood.domain"/>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop>
<prop key="hibernate.max_fetch_depth">3</prop>
<prop key="hibernate.jdbc.fetch_size">50</prop>
<prop key="hibernate.jdbc.batch_size">10</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<context:annotation-config/>
.....
</beans>
感謝
沒有,如果我刪除行,然後我得到的錯誤'錯誤創建在類路徑資源定義名稱「EMF」豆[數據源-TX-jpa.xml]:init方法的調用失敗;嵌套異常是java.lang.IllegalStateException:沒有持久化單元從{classpath *:META-INF/persistence.xml}解析' – Basit
創建一個persitence.xml,在META-INF中,我會給你一個樣例 –
謝謝。我試過,但現在我得到以下異常'產生的原因:org.springframework.beans.factory.BeanCreationException:錯誤創建在類路徑資源[數據源-TX-jpa.xml]定義的名稱「EMF」豆:初始化的調用方法失敗;嵌套異常是java.lang.AbstractMethodError:org.springframework.orm.jpa.persistenceunit.SpringPersistenceUnitInfo.getSharedCacheMode()Ljavax /持久/ SharedCacheMode;' – Basit