【问题标题】:applicationContext.xml and other configuration files - where should they go?applicationContext.xml 和其他配置文件——它们应该放在哪里?
【发布时间】:2011-05-04 11:21:17
【问题描述】:

我正在开发一个新的 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 是正确的地方。

【问题讨论】:

    标签: hibernate spring maven-2 jpa


    【解决方案1】:
    • 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>
      

    请注意,对于单元测试,您可以通过将 test-alternatives 放在 src/test/** 中来覆盖这些文件

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-18
      • 2015-03-10
      • 1970-01-01
      • 2011-06-10
      • 2013-06-07
      相关资源
      最近更新 更多