title: Can configure and start embedded Tomcat via Spring? OK with Jetty?
body: <p>Is there a way to configure and setup Embedded Tomcat in Spring? I can do so easily with Jetty 7 that I created a standalone Java application that will start Jetty as webcontainer and finally JUnit test can call the BO via HTTPInvoker.</p>
  
  <p>To me, it seems I have to write code to do so by using Tomcat?</p>
  
  <h1>Spring xml file</h1>
  
  <pre><code>&lt;!-- Manually start server after setting parent context. (init-method="start") --&gt;
  &lt;bean id="jettyServer"
        class="org.eclipse.jetty.server.Server"
        init-method="start"
        destroy-method="stop"&gt;
      &lt;property name="threadPool"&gt;
          &lt;bean id="ThreadPool"
                class="org.eclipse.jetty.util.thread.ExecutorThreadPool"&gt;
              &lt;constructor-arg value="0" /&gt;
              &lt;!--property name="corePoolSize" value="${jetty.server.thread.pool.core.pool.size}"/&gt;
              &lt;property name="maximumPoolSize" value="${jetty.server.thread.pool.max.pool.size}"/--&gt;
          &lt;/bean&gt;
      &lt;/property&gt;
      &lt;property name="connectors"&gt;
          &lt;list&gt;
              &lt;bean id="Connector"
                    class="org.eclipse.jetty.server.nio.SelectChannelConnector"
                    p:port="${jetty.server.port}"
                    p:maxIdleTime="${jetty.server.max.idle.time}"
                    p:acceptors="${jetty.server.acceptor.num}"
                    p:confidentialPort="${jetty.server.ssl.port}" /&gt;
          &lt;/list&gt;
      &lt;/property&gt;
  
      &lt;property name="handler"&gt;
          &lt;bean class="org.eclipse.jetty.server.handler.HandlerCollection"&gt;
              &lt;property name="handlers"&gt;
                  &lt;list&gt;
                     &lt;bean class="org.eclipse.jetty.servlet.ServletContextHandler"&gt;
                        &lt;property name="contextPath" value="/"/&gt;
                        &lt;property name="sessionHandler"&gt;
                          &lt;bean class="org.eclipse.jetty.server.session.SessionHandler"/&gt;
                        &lt;/property&gt;
                        &lt;property name="resourceBase" value="."/&gt;
                        &lt;property name="servletHandler"&gt;
                          &lt;bean class="org.eclipse.jetty.servlet.ServletHandler"&gt;
                            &lt;property name="servlets"&gt; &lt;!-- servlet definition --&gt;
                              &lt;list&gt;
                              &lt;!-- default servlet --&gt;
                              &lt;bean class="org.eclipse.jetty.servlet.ServletHolder"&gt;
                                &lt;property name="name" value="DefaultServlet"/&gt;
                                &lt;property name="servlet"&gt;                                    
                                    &lt;bean class="org.springframework.web.servlet.DispatcherServlet"/&gt;
                                &lt;/property&gt;
                                &lt;property name="initParameters"&gt;
                                  &lt;map&gt;                                        
                                      &lt;entry key="contextConfigLocation" value="classpath:config/DefaultServlet-servlet.xml" /&gt;
                                  &lt;/map&gt;
                                &lt;/property&gt;
                              &lt;/bean&gt;
                              &lt;/list&gt;
                            &lt;/property&gt;
                            &lt;property name="servletMappings"&gt;
                              &lt;list&gt;&lt;!-- servlet mapping --&gt;
                              &lt;bean class="org.eclipse.jetty.servlet.ServletMapping"&gt;
                                &lt;property name="pathSpecs"&gt;
                                  &lt;list&gt;&lt;value&gt;/&lt;/value&gt;&lt;/list&gt;
                                &lt;/property&gt;
                                &lt;property name="servletName" value="DefaultServlet"/&gt;
                              &lt;/bean&gt;
                              &lt;/list&gt;
                            &lt;/property&gt;
                          &lt;/bean&gt;
                        &lt;/property&gt;
                      &lt;/bean&gt;
  
                      &lt;bean class="org.eclipse.jetty.server.handler.RequestLogHandler"&gt;
                          &lt;property name="requestLog"&gt;
                              &lt;bean class="org.eclipse.jetty.server.NCSARequestLog"&gt;
                                  &lt;constructor-arg value="${jetty.server.log.dir}/jetty-yyyy_mm_dd.log"/&gt;
                                  &lt;property name="extended" value="false"/&gt;
                              &lt;/bean&gt;
                          &lt;/property&gt;
                      &lt;/bean&gt;
                  &lt;/list&gt;
              &lt;/property&gt;
          &lt;/bean&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <h1>DefaultServlet-servlet.xml</h1>
  
  <pre><code>&lt;!-- This default handler takes care of each of the services enumerated below --&gt;
      &lt;bean id="defaultHandlerMapping"
              class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" /&gt;
  
      &lt;bean id="helloService" class="com.company.ws.bo.HelloServiceImpl"/&gt;
  
      &lt;!-- SpringHTTP Service Exposure --&gt;
  
      &lt;bean name="/HelloService"
              class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter"
              lazy-init="true"&gt;
              &lt;property name="service" ref="helloService" /&gt;
              &lt;property name="serviceInterface"
                      value="com.company.ws.bo.IHelloService" /&gt;
      &lt;/bean&gt;
  </code></pre>