applicationContext.xml和其他配置文件 - 它们应该去哪里?

时间:2010-11-03 12:24:41

标签: hibernate spring maven-2 jpa

我正在开发一个新的Spring + JPA2 / Hibernate + Wicket项目,我想知道一些配置文件应该去哪里?

的applicationContext.xml 我在src / main / resources / META-INF和src / main / resources /

中都看到过这个

的persistence.xml 大多数时候,我在src / main / resources / META-INF中看到过它。就我而言,它包含以下内容:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
 version="1.0">
 <persistence-unit name="ApplicationEntityManager" transaction-type="RESOURCE_LOCAL">
  <provider>org.hibernate.ejb.HibernatePersistence</provider> 
 </persistence-unit>
</persistence>

的web.xml 我想src / main / webapp / WEB-INF是正确的地方。

1 个答案:

答案 0 :(得分:4)

  • persistence.xml必须在src/main/resources/META-INF
  • applicationContext.xml可以在任何地方,只要您使用contextConfigLocation进行配置即可。默认情况下,spring会在WEB-INF中查找它,因此它必须位于src/main/webapp/WEB-INF中。但我认为最好是src/main/resources

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>
    

请注意,对于单元测试,您可以通过将测试替代项放在src/test/**

中来覆盖这些文件

一般来说,所有资源都应该在src/main/resources。 (在META-INF