无法使用Spring JPA连接到Oracle数据库

时间:2019-04-25 13:25:19

标签: spring oracle spring-data-jpa

我正在尝试使用SpringJPA连接到Oracle DB。并得到以下错误:

SLF4J:有关更多详细信息,请参见http://www.slf4j.org/codes.html#StaticLoggerBinder。 org.springframework.beans.factory.BeanCreationException:创建文件[C:\ Users \ Shivani.kumari \ ssdp \ SSDP_DB \ spring.xml]中定义的名称为'entityManagerFactoryBean'的bean时出错:bean的实例化失败;嵌套的异常是org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]:构造方法抛出了异常;嵌套异常是java.lang.NoClassDefFoundError:无法初始化类org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1303)     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1197)     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)上     在org.springframework.beans.factory.support.AbstractBeanFactory.lambda $ doGetBean $ 0(AbstractBeanFactory.java:320)     在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)     在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)     在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)     在org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105)     在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)     在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)     在org.springframework.context.support.FileSystemXmlApplicationContext。(FileSystemXmlApplicationContext.java:142)     在org.springframework.context.support.FileSystemXmlApplicationContext。(FileSystemXmlApplicationContext.java:85)     在com.avaya.ssdp.db.Testing.main(Testing.java:15) 原因:org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]:构造方法抛出异常;嵌套异常是java.lang.NoClassDefFoundError:无法初始化类org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager     在org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:184)     在org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1295)     ...另外13个 原因:java.lang.NoClassDefFoundError:无法初始化类org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager     在org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean。(LocalContainerEntityManagerFactoryBean.java:96)     在sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)处     在sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)     在sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)     在java.lang.reflect.Constructor.newInstance(Constructor.java:423)     在org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:172)     ...另外15个

下面是我的POM.XML:

http://maven.apache.org/xsd/maven-4.0.0.xsd“>     4.0.0     com.test.test     test_db     0.0.1-快照     

    <!-- JUnit testing framework -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>




    <dependency>
        <groupId>com.hynnet</groupId>
        <artifactId>oracle-driver-ojdbc14</artifactId>
        <version>12.1.0.1</version>
    </dependency>
    <!-- Spring AOP dependency -->
    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>2.2</version>
    </dependency>

    <!-- MySQL database driver -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.9</version>
    </dependency>


    <!-- Hibernate framework -->
    <dependency>
        <groupId>hibernate</groupId>
        <artifactId>hibernate3</artifactId>
        <version>3.2.3.GA</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate.common</groupId>
        <artifactId>hibernate-commons-annotations</artifactId>
        <version>4.0.4.Final</version>
    </dependency>

    <!-- Hibernate library dependecy start -->
    <dependency>
        <groupId>dom4j</groupId>
        <artifactId>dom4j</artifactId>
        <version>1.6.1</version>
    </dependency>

    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.1.1</version>
    </dependency>

    <dependency>
        <groupId>commons-collections</groupId>
        <artifactId>commons-collections</artifactId>
        <version>3.2.1</version>
    </dependency>

    <dependency>
        <groupId>antlr</groupId>
        <artifactId>antlr</artifactId>
        <version>2.7.7</version>
    </dependency>
    <dependency>
        <groupId>commons-dbcp</groupId>
        <artifactId>commons-dbcp</artifactId>
        <version>1.4</version>
    </dependency>
    <dependency>
        <groupId>javassist</groupId>
        <artifactId>javassist</artifactId>
        <version>3.12.1.GA</version>
    </dependency>
    <!-- Hibernate library dependecy end -->
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.0-api</artifactId>
        <version>1.0.1.Final</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>5.1.6.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>5.1.6.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>5.1.6.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>5.1.6.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>5.1.6.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>5.1.6.RELEASE</version>
    </dependency>
    <!-- CGLIB is required to process @Configuration classes -->
    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>2.2.2</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>1.11.3.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.1.9.Final</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-tx -->
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>5.1.6.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.1.9.Final</version>
    </dependency>



</dependencies>

以下是我的SPRING.XML:

http://www.springframework.org/schema/beans/spring-beans.xsd        http://www.springframework.org/schema/security        http://www.springframework.org/schema/security/spring-security.xsd        http://www.springframework.org/schema/context        http://www.springframework.org/schema/context/spring-context.xsd        http://www.springframework.org/schema/data/jpa        http://www.springframework.org/schema/data/jpa/spring-jpa.xsd“>

<context:component-scan base-package="com.test.test.db"></context:component-scan>
<jpa:repositories base-package="com.test.test.db.repository"
    entity-manager-factory-ref="entityManagerFactoryBean"></jpa:repositories>

<!--EntityManagerFactory -->
<beans:bean id="entityManagerFactoryBean"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <beans:property name="dataSource" ref="dataSource" />
    <!-- This makes /META-INF/persistence.xml is no longer necessary -->
    <beans:property name="packagesToScan" value="com.test.test.db.repository" />
    <beans:property name="jpaVendorAdapter">
        <beans:bean
            class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
    </beans:property>
    <beans:property name="jpaProperties">
        <beans:props>
            <beans:prop key="hibernate.hbm2ddl.auto">update</beans:prop>
            <beans:prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect
            </beans:prop>
        </beans:props>
    </beans:property>
</beans:bean>
<beans:bean id="transactionManager"
    class="org.springframework.orm.jpa.JpaTransactionManager">
    <beans:property name="entityManagerFactory" ref="entityManagerFactoryBean" />
</beans:bean>
<beans:bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <beans:property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
    <beans:property name="url"
        value="jdbc:com.test.test.db:1521:qa1test " />
    <beans:property name="username" value="testuser" />
    <beans:property name="password" value="testpassword" />
</beans:bean>

0 个答案:

没有答案