Investigated JSP support

Summary: Tomcat works with WARs. Jetty doesn't work.

See gh-367
This commit is contained in:
Dave Syer
2014-02-18 12:14:25 +00:00
parent da26c614f2
commit b088f60082
3 changed files with 26 additions and 24 deletions

View File

@@ -249,29 +249,22 @@ can also register items directly if your bean implements the `ServletContextInit
interface.
### JSP limitations
When running a Spring Boot application that uses an embedded servlet container and is
packaged as an executable JAR or WAR, there are some limitations in the JSP support.
### JSP limitations When running a Spring Boot application that uses
an embedded servlet container and is packaged as an executable
archive, there are some limitations in the JSP support.
Due to the way that Jasper (Tomcat and Jetty's JSP engine) loads tag libraries, tag
libraries packaged in JAR files nested within the JAR or WAR will not work correctly.
When packaged and run as an executable JAR, you will see an error message produced during
application startup that is similar to the following:
* With Tomcat it should work if you use WAR packaging. I.e. an
executable WAR will work, and will also be deployable to a standard
container (Tomcat included). An executable JAR will not work because
of a hard coded file patter in Tomcat itself.
* Jetty does not currently work as an embedded container with
JSPs. There should be a way to make it work, so hopefully someone
can figure it out (pull requests always welcome).
> org.apache.jasper.JasperException: The absolute uri: http://www.springframework.org/tags
> cannot be resolved in either web.xml or the jar files deployed with this application
When packaged and run as an executable WAR, you will see an error message produced during
application startup that is similar to the following:
> java.io.FileNotFoundException: JAR entry
> WEB-INF/lib-provided/tomcat-embed-jasper-7.0.47.jar!/javax/servlet/jsp/resources/web-jsptaglibrary_1_2.dtd
> not found in my-app.war
To avoid these limitations, rather than using the embedded servlet container support,
package your application as a traditional (non-executable) WAR file and deploy it to a
servlet container. Alternatively, you may want to consider using an alternative view
technology.
There is a
[JSP sample](https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-web-jsp)
so you can see how to set things up.
## Using YAML instead of Properties
[YAML](http://yaml.org) is a superset of JSON, and as such is a very convenient format

View File

@@ -304,7 +304,7 @@ public abstract class AbstractEmbeddedServletContainerFactory implements
// Or maybe there is a document root in a well-known location
file = file != null ? file : getCommonDocumentRoot();
if (file == null && this.logger.isWarnEnabled()) {
this.logger.debug("None of the document roots "
this.logger.info("None of the document roots "
+ Arrays.asList(COMMON_DOC_ROOTS)
+ " point to a directory and will be ignored.");
}
@@ -340,7 +340,11 @@ public abstract class AbstractEmbeddedServletContainerFactory implements
}
private File getWarFileDocumentRoot() {
return getArchiveFileDocumentRoot(".war");
File file = getArchiveFileDocumentRoot(".war");
if (file != null) {
return file;
}
return getArchiveFileDocumentRoot(".jar");
}
private File getCommonDocumentRoot() {

View File

@@ -131,7 +131,12 @@ public class JettyEmbeddedServletContainerFactory extends
File root = getValidDocumentRoot();
if (root != null) {
try {
handler.setBaseResource(Resource.newResource(root));
if (!root.isDirectory()) {
handler.setBaseResource(Resource.newClassPathResource(""));
}
else {
handler.setBaseResource(Resource.newResource(root));
}
}
catch (Exception ex) {
throw new IllegalStateException(ex);