簡體   English   中英

實體管理器工廠名稱已注冊

[英]Entity manager factory name is already registered

我有一個服務器設置,它在運行時可以正常運行,但是在啟動期間,我收到了所有消息 2 次,並且 Hibernate 發出警告說Entity manager factory name is already registered 我正在使用 Spring、Hibernate 和 CXF。 我覺得我的設置應該符合文檔,但它一定是我缺少的東西。 我發現了很多類似的案例,人們指向 Spring MVC,但我認為這不是我的問題。

在我的 web.xml 我有:

<listener>
    <description>desc</description>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
    <listener-class>
        org.springframework.web.context.request.RequestContextListener
    </listener-class>
</listener>

<servlet>
    <servlet-name>cxf</servlet-name>
    <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

我在 WEB-INF 中有以下內容:

  • applicationContext.xml帶有組件掃描到@Configuration類的 java-config 和組件掃描@Component
  • cxf-servlet.xml也帶有組件掃描。

是我錯過了什么嗎?


更新 1:如果我從 cxf-servlet.xml 中刪除組件掃描,問題似乎就會消失,但是它無法使用@Inject處理我的@Configurable類。 現在我對 CXF 和 Spring 如何啟動 Spring 上下文更加困惑。

更新 2:這與在 cxf-servlet 和 applicationContext 中進行組件掃描有關。 一切正常,但它在啟動時加載了 2 次。

嘗試過濾掉用@Component 注釋的 Hibernate pojo 類/包,並嘗試確保創建實體管理器 bean 的類/包也被過濾掉。

在以下聲明的情況下,默認掃描用@Component 注釋的類。

<context:component-scan base-package="com.abc.xyz" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM