I prefer to configure spring with xml files. The question is, how they should be named and where should be located.
The official spring documentation do not provide any recommendation. Here are some with I advocate.
Name consistency
Start all files with the same prefix applicationConfig*.xml
E.g. applicationConfig-security.xml
, applicationConfig-hibernate.xml
, applicationConfig-quartz.xml
etc.
File Location
- JAR ->
src/main/resources/META-INF/spring
- WAR ->
src/main/webapp/WEB-INF/spring
Do not use version number in schema reference
Instead of
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> ... </beans>
Use this
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> ... </beans>
Why?
Spring automatically use highest version available from maven dependencies. Upgrade to newer version of spring is much more easy.
Žádné komentáře:
Okomentovat