perwendel / spark

A simple expressive web framework for java. Spark has a kotlin DSL https://github.com/perwendel/spark-kotlin
Apache License 2.0
9.64k stars 1.56k forks source link

Add documentation SparkFilter annotation-style configuration instructions #1081

Closed daggerok closed 5 years ago

daggerok commented 5 years ago

Hello,

I found in documentation web.xml configuration like this:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1"
         xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">

  <display-name>Blog Application</display-name>

  <filter>
    <filter-name>SparkBlogFilter</filter-name>
    <filter-class>spark.servlet.SparkFilter</filter-class>
    <init-param>
      <param-name>applicationClass</param-name>
      <param-value>com.github.daggerok.ui.BlogApplication</param-value>
    </init-param>
  </filter>

  <filter-mapping>
    <filter-name>SparkBlogFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>

But, I cannot find sources for spark java documentation to create PR, so please add also annotation-style configuration to avoid using web.xml file at all:

// ...
import static spark.servlet.SparkFilter.APPLICATION_CLASS_PARAM;

@WebFilter(
    urlPatterns = "/*",
    filterName = "SparkBlogFilter",
    displayName = "Blog Application",
    initParams = @WebInitParam(
        name = APPLICATION_CLASS_PARAM,
        value = "com.github.daggerok.ui.BlogApplication"
    )
)
public class SparkBlogFilter extends spark.servlet.SparkFilter { }

-- Regards, Maksim

perwendel commented 5 years ago

The web.xml is only necessary if you want to run Spark on a standalone webserver and not embedded which is the default and preferred use. What is the case in your situation? Anyhow, the feature might still be valid.

daggerok commented 5 years ago

My case was about running app in application server. You can ignore it if you think it’s useless