我收到以下错误获取错误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