Embedded tomcat 7 servlet 3.0 annotations not working

后端 未结 4 705
孤独总比滥情好
孤独总比滥情好 2020-12-01 03:19

I have a stripped down test project which contains a Servlet version 3.0, declared with annotations like so:

    @WebServlet(\"/test\")
public class TestServ         


        
4条回答
  •  青春惊慌失措
    2020-12-01 03:34

    Given the JNDI magic in the snippet you posted:

    try {
        listBindings = context.getResources().listBindings(
                "/WEB-INF/classes");
    } catch (NameNotFoundException ignore) {
        // Safe to ignore
    }
    

    could you maybe set up the same sort of entries in JNDI yourself?

    Context ctx = tomcat.addWebapp(...);
    FileDirContext fdc = new FileDirContext();
    fdc.setDocBase(new File("/path/to/my/classes").getAbsolutePath());
    ctx.getResources().createSubcontext("/WEB-INF/classes").bind("myclasses", fdc);
    

提交回复
热议问题