servlets - Jetty + Jersey + Spring DI with no web.xml -


i trying write small rest application using embedded jetty 9 server , jersey (2.18) servlet. use spring 4 dependency injection, having troubles inject spring beans in jersey resources. configuring server programmatically, no web.xml.

my jersey resource config is:

public class applicationconfig extends resourceconfig {    public static final string root_package = "com.example";    public applicationconfig() {     packages(true, root_package);      // features     register(jacksonfeature.class);      property(metainf_services_lookup_disable, true);    } } 

the main class (where i'm configuring , starting jetty) is:

public class runner {    public static void main(string[] args) {     applicationconfig applicationconfig = new applicationconfig();      servletholder jerseyservlet = new servletholder(new servletcontainer(applicationconfig));      servletcontexthandler context = new servletcontexthandler();      context.setcontextpath("/");     context.addservlet(jerseyservlet, "/rest/*");      context.addeventlistener(new contextloaderlistener());     context.addeventlistener(new requestcontextlistener());      context.setinitparameter("contextclass", annotationconfigwebapplicationcontext.class.getname());     context.setinitparameter("contextconfiglocation", productionspringconfig.class.getname());      server server = new server(8080);     server.sethandler(context);      try {       server.start();       server.join();     } catch (exception e) {       e.printstacktrace();     }    } } 

the spring configurations is:

@configuration @componentscan("com.example") public class productionspringconfig {} 

i have added simple spring component in scanned package , can see correctly instantiated when server starts:

@component public class beanexample {    public void dosomething(){     system.out.println("helloworld");   } } 

when try inject jersey resource though, null. tried using both autowired , inject annotations. i'm pretty sure misunderstood , didn't configure pieces properly.

could please?


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -