응용 프로그램 컨텍스트에있는 bean을 사용하여 엔티티 관리자를 연결하는 데 문제가 있습니다. 내가 어떤 작업을 수행 할 때마다 NullPointerException이 발생합니다. applicationContext bean으로 entityManager를 연결할 수 없습니다.
이
이가있는 내가 엔티티 관리자를 만드는 오전 자바 파일 내 applicationContext.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:context="http://www.springframework.org/schema/context"
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.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.ajit.retail"/>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.postgresql.Driver"/>
<property name="url" value="jdbc:postgresql://localhost/retail"/>
<property name="username" value="retail_user"/>
<property name="password" value="password"/>
</bean>
<bean id="entityManagerOne" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true"/>
<property name="databasePlatform" value="org.hibernate.dialect.PostgreSQL82Dialect"/>
</bean>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerOne"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
이다 내가이 엔티티 관리자를 사용할 때마다
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
public class AbstractRepository {
@PersistenceContext
EntityManager entityManager;
}
그래서 널 포인터 예외를 제공합니다 도와주세요!
나는 그것을 변경했지만 여전히 동일한 문제를 일으켰습니다. : –
'AbstractRepository'파일의 정확한 패키지를 제공 할 수 있습니까? 'com.ajit.retail'패키지 만 검색하고 있습니다. – Kartoch
내 대답을 업데이트했습니다. 확인하십시오. – Kartoch