2015-01-20 4 views
0

저는 봄과 JPA 프로젝트에 참여하고 있습니다. Persistence.xml에서 JPA Persistence Unit을 구성했으며 여기에 스프링 구성 파일이 있습니다.스프링은 현재 persistenceUnitName을 어떻게 감지합니까?

내 응용 프로그램은 정상적으로 작동하지만 Spring Framework에서 Persistence.xml 파일에 정의 된 Persistence Unit을 감지하고 Spring Bean 구성 파일에 정의되지 않은 상태로 삽입하는 방식을 이해하지 못했습니다.

아무에게도 대답 해 줄 수 있습니까?

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

    <context:annotation-config/> 
    <context:component-scan base-package="ma.professionalpartners.fireAppBusiness.dao"/> 

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"> 
     <property name="persistenceUnitName" value="fireApp-Domain" /> 
    </bean> 

    <bean id="jpaTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> 
     <property name="entityManagerFactory" ref="entityManagerFactory" /> 
    </bean> 

    <tx:annotation-driven transaction-manager="jpaTransactionManager" /> 

</beans> 

답변

0

당신은 퍼시스턴스 유닛의 이름을 제공 한 EntityManagerFactory에 콩 구성 할 때 : 봄은 단순히 그 위치에서 검색 할 수 있도록

<property name="persistenceUnitName" value="fireApp-Domain" /> 
+0

답장을 보내 주셔서 감사합니다. 그렇습니다.하지만 스프링 구성 파일에 id = "fireApp-Domain"이라는 빈을 정의하지 않았습니다. 단지 persistence.xml에있는 PU의 이름 일뿐입니다. Persistence.xml과 스프링 구성 파일 사이에 어떤 관계가 있습니까? –

+0

빈을 정의 할 필요가 없습니다. Spring은 기본 위치 (META-INF/persistence.xml)에서 persistence.xml을 찾는다. 지정한 이름으로 지속성 단위를 찾으면 생성합니다. – dunni

0

persistence.xml 파일이 특정 경로에 있어야합니다. 파일을 찾은 후 XML 컨텐트를 파싱하고, 하나의 PersistenceUnit이있는 경우이 컨텐트가 기본 컨텐트로 만들어집니다. 물론 이름을 지정하면 (그랬던 것처럼), PersistenceUnit을 정확하게 찾습니다.

관련 문제