Add web-fragment.xml to spring-web
The servlet spec treats any jar in WEB-INF/lib as a web fragment: "A plain old jar file in the WEB-INF/lib directory with no web- fragment.xml is also considered a fragment" (section 8.2.1) This change adds a web-fragment.xml giving the web fragment an explicit name, "spring_web", and indicating there is no need to scan for Servlet annotations in the spring-web.jar itself through metadata-complete=true. This allows applications that choose to include only specific web fragments, through the <absolute-ordering> element in web.xml to also include the "spring_web" fragment, in order to enable scanning for WebApplicationInitializer types.
This commit is contained in:
@@ -52,6 +52,22 @@ import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
||||
* processed unless the {@code <web-app>} element's {@code version} attribute is >= "3.0"
|
||||
* and the {@code xsi:schemaLocation} for "http://java.sun.com/xml/ns/javaee" is set to
|
||||
* "http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd".
|
||||
* <p>A web application can choose to limit the amount of classpath scanning the Servlet
|
||||
* container does at startup either through the metadata-complete attribute in
|
||||
* {@code web.xml}, which controls scanning for Servlet annotations or through an
|
||||
* {@code <absolute-ordering>} element also in {@code web.xml}, which controls which
|
||||
* web fragments (i.e. jars) are allowed to perform a {@code ServletContainerInitializer}
|
||||
* scan. When using this feature, the Spring's {@link SpringServletContainerInitializer}
|
||||
* can be enabled by adding "spring_web" to the list of named web fragments in
|
||||
* {@code web.xml} as follows:
|
||||
*
|
||||
* <pre class="code">
|
||||
* {@code
|
||||
* <absolute-ordering>
|
||||
* <name>some_web_fragment</name>
|
||||
* <name>spring_web</name>
|
||||
* </absolute-ordering>
|
||||
* }</pre>
|
||||
*
|
||||
* <h2>Relationship to Spring's {@code WebApplicationInitializer}</h2>
|
||||
* Spring's {@code WebApplicationInitializer} SPI consists of just one method:
|
||||
@@ -91,6 +107,7 @@ import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @author Juergen Hoeller
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 3.1
|
||||
* @see #onStartup(Set, ServletContext)
|
||||
* @see WebApplicationInitializer
|
||||
|
||||
9
spring-web/src/main/resources/META-INF/web-fragment.xml
Normal file
9
spring-web/src/main/resources/META-INF/web-fragment.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<web-fragment xmlns="http://java.sun.com/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd"
|
||||
version="3.0" metadata-complete="true">
|
||||
|
||||
<name>spring_web</name>
|
||||
|
||||
</web-fragment>
|
||||
Reference in New Issue
Block a user