김명준
김명준

Reputation: 363

Spring STS javax/persistence/EntityManagerFactory can not found

I want connect my Spring project to DB with jpa

I added this code. jsp.xml

<?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: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/tx 
  http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">

<bean id="myEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
  <property name="dataSource" ref="dataSource" />
  <property name="packagesToScan" value="org.baeldung.persistence.model" />
  <property name="jpaVendorAdapter">
     <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
  </property>
  <property name="jpaProperties">
     <props>
        <prop key="hibernate.hbm2ddl.auto">create-drop</prop>
        <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
     </props>
  </property>
</bean>

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  <property name="driverClassName" value="com.mysql.jdbc.Driver" />
  <property name="url" value="mysql://kimdg3550.cafe24.com/kimdg3550" />
   <property name="username" value="secret" />
   <property name="password" value="secret" />
</bean>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
  <property name="entityManagerFactory" ref="myEmf" />
</bean>
 <tx:annotation-driven />

<bean id="persistenceExceptionTranslationPostProcessor"
  class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />

</beans>

But I get this error

enter image description here

Build path is incomplete. Cannot find class file for javax/persistence/EntityManagerFactory jsp.xml /spring/src/main/webapp/WEB-INF/spring/appServlet line 32 Spring AOP Problem

How can I avoid this error?

Upvotes: 1

Views: 2980

Answers (2)

김명준
김명준

Reputation: 363

I solved this error by adding this code to pom.xml

<dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
</dependency>

Upvotes: 0

WeMakeSoftware
WeMakeSoftware

Reputation: 9162

to solve this problem you have to add one of the JPA implementations to your classpath. Hibernate is one of the mainstream implementations of JPA standard.

Upvotes: 1

Related Questions