http://undertow.io/downloads.htmlhttp://undertow.io/downloads.htmlHallo Community,
ich versuche gerade eine Spring 4 / JSF 2.2 / Primefaces Webapp, welche auf dem Tomcat 7 sauber läuft im Undertow (embedded) zum laufen zu bringen. Leider scheitert es an den XML Files für Spring. Folgende Web.xml:
[xml]<?xml version="1.0" encoding="UTF-8"?>
contextConfigLocation
/WEB-INF/spring/root-context.xml
/WEB-INF/spring/applicationContext-security.xml
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<!-- <param-value>opo-theme</param-value> <param-value>light-blue</param-value> <param-value>light-yellow</param-value> <param-value>light-grey</param-value> <param-value>bootstrap</param-value>
<param-value>none</param-value> -->
<param-value>delta</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
</welcome-file-list>
[/xml]
Versuche ich so mit Undertow zu starten:
import static io.undertow.servlet.Servlets.deployment;
import static io.undertow.servlet.Servlets.servlet;
import io.undertow.Handlers;
import io.undertow.Undertow;
import io.undertow.server.HttpHandler;
import io.undertow.server.handlers.PathHandler;
import io.undertow.servlet.api.DeploymentInfo;
import io.undertow.servlet.api.DeploymentManager;
import io.undertow.servlet.api.ListenerInfo;
import javax.faces.webapp.FacesServlet;
import javax.servlet.ServletException;
import org.apache.log4j.Logger;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.request.RequestContextListener;
import org.springframework.web.servlet.DispatcherServlet;
public class EmbeddedStart {
private static final String MYAPP = "/";
Logger log = Logger.getLogger(getClass());
public void start() throws ServletException {
log.debug("Prepare Undertow start");
DeploymentInfo servletBuilder = deployment()
.setClassLoader(getClass().getClassLoader())
.setContextPath(MYAPP)
.setDeploymentName("webgui.war")
.addInitParameter("contextConfigLocation", "/WEB-INF/spring/root-context.xml
/WEB-INF/spring/applicationContext-security.xml")
.addInitParameter("primefaces.THEME", "delta")
.addWelcomePage("index.html")
.addWelcomePage("index.htm")
.addServlets(
servlet("appServlet", DispatcherServlet.class).setLoadOnStartup(1)
.addInitParam("contextConfigLocation", "/WEB-INF/spring/appServlet/servlet-context.xml").addMapping("/"),
servlet("Faces Servlet", FacesServlet.class).setLoadOnStartup(1).addMapping("*.html"))
.addListener(new ListenerInfo(ContextLoaderListener.class)).addListener(new ListenerInfo(RequestContextListener.class));
DeploymentManager manager = defaultContainer().addDeployment(servletBuilder);
manager.deploy();
HttpHandler servletHandler = manager.start();
PathHandler path = Handlers.path(Handlers.redirect(MYAPP)).addPrefixPath(MYAPP, servletHandler);
Undertow server = Undertow.builder().addListener(8080, "localhost").setHandler(path).build();
log.debug("Undertow start");
server.start();
log.debug("Undertow started");
}
public static void main(String[] args) throws ServletException {
EmbeddedStart es = new EmbeddedStart();
es.start();
}
}
leider steigt die Anwendung bei manager.deploy();
mit einer Exception aus:
ERROR: 319 org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/spring/root-context.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/spring/root-context.xml]
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:343)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:216)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:187)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:540)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:454)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:173)
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:182)
at org.pcss.undertow.EmbeddedStart.start(EmbeddedStart.java:39)
at org.pcss.undertow.EmbeddedStart.main(EmbeddedStart.java:50)
Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/spring/root-context.xml]
at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:140)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:329)
... 16 more
ich habe auch schon unterschiedliche Ordner ab der Ebene “src” versucht. Allerdings ohne positives Ergebnis. Warum kann der Tomcat die Files lesen, und Undertow nicht?
Undertow habe ich via Maven eingesetzt: http://undertow.io/downloads.html
Als Einleitung habe ich das Example Projekt auf github gesichtet: https://github.com/undertow-io/undertow/blob/master/examples/src/main/java/io/undertow/examples/servlet/ServletServer.java
*** Edit ***
PS: Dieselbe Fehlermeldung erhalte ich, wenn ich absolute Pfade angebe.