小编Dun*_*can的帖子

Spring 3.1 WebApplicationInitializer和Embedded Jetty 8 AnnotationConfiguration

我正在尝试使用Spring 3.1和嵌入式Jetty 8服务器创建一个没有任何XML配置的简单webapp.

但是,我正在努力让Jetty认识到我对Spring WebApplicationInitializer接口的实现.

项目结构:

src
 +- main
     +- java
     |   +- JettyServer.java
     |   +- Initializer.java
     | 
     +- webapp
         +- web.xml (objective is to remove this - see below).
Run Code Online (Sandbox Code Playgroud)

上面的Initializer类是WebApplicationInitializer的一个简单实现:

import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import org.springframework.web.WebApplicationInitializer;

public class Initializer implements WebApplicationInitializer {

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        System.out.println("onStartup");
    }
}
Run Code Online (Sandbox Code Playgroud)

同样JettyServer是嵌入式Jetty服务器的简单实现:

import org.eclipse.jetty.annotations.AnnotationConfiguration;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.Configuration;
import org.eclipse.jetty.webapp.WebAppContext;

public class JettyServer {

    public static void main(String[] args) throws …
Run Code Online (Sandbox Code Playgroud)

java jetty spring-mvc embedded-jetty jetty-8

33
推荐指数
3
解决办法
3万
查看次数

标签 统计

embedded-jetty ×1

java ×1

jetty ×1

jetty-8 ×1

spring-mvc ×1