嗨,我编写了一个小应用程序并尝试连接 jpa。 在我的 spring 配置文件中我这样写:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driver.manager}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.login}" />
<property name="password" value="${jdbc.password}" />
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="packagesToScan">
<list>
<value>com.epam.newsmanagement.entity</value>
</list>
</property>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="ORACLE" />
</bean>
</property>
</bean>
<bean id="jpaDao" class="com.epam.newsmanagement.dao.JPANewsDao" />
当我启动应用程序时,浏览器显示 404 错误,控制台给出这样的错误
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/jpa-configuration.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'dataSource' of bean class [org.springframework.orm.jpa.LocalEntityManagerFactoryBean]: Bean property 'dataSource' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
请帮忙)
最佳答案
org.springframework.orm.jpa.LocalEntityManagerFactoryBean 没有定义 dataSource/getDataSource() 字段/方法。这就是为什么你会得到这个异常。
改用 LocalContainerEntityManagerFactoryBean
This可能对你有帮助
关于java - 集成 JPA 和 SpringIOc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13357533/