开发者

applicationContext.xml and other configuration files - where should they go?

开发者 https://www.devze.com 2023-01-23 02:06 出处:网络
I\'m developing a new Spring+JPA2/Hibernate+Wicket project and am wondering where some of the configuration files should go?

I'm developing a new Spring+JPA2/Hibernate+Wicket project and am wondering where some of the configuration files should go?

applicationContext.xml I've seen this both in src/main/resources/META-INF and just src/main/resources/

persistence.xml Most of the time, I've seen it in src/main/resources/META-INF. In my c开发者_JAVA百科ase, it contains the following:

<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 I guess src/main/webapp/WEB-INF is the correct place.


  • persistence.xml must be in src/main/resources/META-INF
  • applicationContext.xml can be anywhere, as long as you configure it with contextConfigLocation. By default spring looks for it in WEB-INF, so it has to be in src/main/webapp/WEB-INF. But I think it better be in src/main/resources.

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

Note that for unit tests you can override these files by placing the test-alternatives in src/test/**

Generally speaking, all resources should be in src/main/resources. (reraly in META-INF)

0

精彩评论

暂无评论...
验证码 换一张
取 消