Integrating Jersey 2 and Spring with Java Based Configuration

后端 未结 4 629
日久生厌
日久生厌 2020-12-30 12:18

I am using Jersey 2.10 and jersey-spring3 and Spring 4. I want to achieve DI(basically services) in jersey resources as well as in other places and want to create Spring Bea

4条回答
  •  借酒劲吻你
    2020-12-30 13:00

    For those trying to do it with Java config:

        public static void main(String[] args) throws IOException {
            HttpServer server = new HttpServer();
            NetworkListener listener = new NetworkListener("grizzly2", "localhost", 2088);
            server.addListener(listener);
    
            WebappContext ctx = new WebappContext("ctx","/");
            final ServletRegistration reg = ctx.addServlet("spring", new SpringServlet());
            reg.addMapping("/*");
            ctx.addContextInitParameter( "contextClass", "org.springframework.web.context.support.AnnotationConfigWebApplicationContext" );
            ctx.addContextInitParameter( "contextConfigLocation", "com.example.AppConfig" );
            ctx.addListener( "org.springframework.web.context.ContextLoaderListener" );
            ctx.addListener("org.springframework.web.context.request.RequestContextListener");
    
            ctx.deploy(server);
    
            server.start();
    
            System.in.read();
    
    }
    

提交回复
热议问题