整合JPA和SpringIOc [英] integrating JPA and SpringIOc

查看:81
本文介绍了整合JPA和SpringIOc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个小型应用程序,并尝试连接jpa. 在我的spring配置文件中,我这样写:

Hi I write small application and trying connect jpa. in my spring configuration file I write this:

<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错误,而控制台给出了这样的错误

and when I start my application browser giges me 404 error and console give such error

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()字段/方法.这就是为什么您遇到该异常的原因.

org.springframework.orm.jpa.LocalEntityManagerFactoryBean does not have a dataSource/ getDataSource() field/method defined. thats why you are getting that exception.

改为使用LocalContainerEntityManagerFactoryBean

use LocalContainerEntityManagerFactoryBean instead

可能对您有帮助

这篇关于整合JPA和SpringIOc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆