there is a maven project with the /WEB-INF/web.xml file of the following content:
<web-app 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-app_2_5.xsd" version="2.5"> <servlet> <servlet-name>baseWebApp</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>baseWebApp</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> applicationContext.xml:
<mvc:annotation-driven/> <context:component-scan base-package="...."/> <mvc:resources mapping="/resources/**" location="/resources/"/> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/pages/" p:suffix=".jsp"/> </beans> The controller is implemented on the basis of annotations.
Being run by mvn -Djetty.port = 9999 jetty: run, the application runs perfectly. I decided to initialize jetty in code, and I can’t manually create a context for jetty. Below is the main class:
public class AppMain { public static void main(String[] args) throws Exception { ServletContextHandler sch = new ServletContextHandler(); /* инициализация контекста .... */ Server jetty = new Server(9999); jetty.setHandler(sch); jetty.start(); } } question: how to initialize context based on web.xml?