Created
October 11, 2011 06:15
-
-
Save rossabaker/1277411 to your computer and use it in GitHub Desktop.
Bootstrap Scalatra from ServletContextListener
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.scalatra.example | |
import org.scalatra._ | |
import javax.servlet._ | |
import javax.servlet.http._ | |
class MyServlet(message: String) extends ScalatraServlet { | |
get("/") { message } | |
} | |
class Bootstrap extends ServletContextListener { | |
def contextDestroyed(ev: ServletContextEvent) = {} | |
def contextInitialized(ev: ServletContextEvent) = { | |
val ctx = ev.getServletContext | |
val reg = ctx.addServlet("my-servlet", new MyServlet("constructor injected")) | |
reg.addMapping("/*") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<web-app version="2.5" 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"> | |
<listener> | |
<listener-class>org.scalatra.example.Bootstrap</listener-class> | |
</listener> | |
</web-app> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment