Unable to Import persistence.xml within applicationContext.xml file

后端 未结 3 1488
既然无缘
既然无缘 2021-01-17 02:58

I\'m using eclipse juno IDE I have Java application which have src folder. within the folder I have:

1) applicationContext.xml

2) persistence.xml

I a

3条回答
  •  走了就别回头了
    2021-01-17 03:30

    Your attempt to use persistence.xml as a Spring config makes absolutely no sense, because persistence.xml is not a Spring config.

    If you want to use JPA with Spring, you need to put persistence.xml into META-INF folder inside your source folder, and declare LocalContainerEntityManagerFactory in applicationContext.xml:

    
        
    
    

    Then you can inject EntityManager into your Spring bean using @PersistenceContext:

    @PersistenceContext
    private EntityManager em;
    

    See also:

    • 13.5 JPA

提交回复
热议问题