简体   繁体   English

在 maven jetty 插件中使用 @WebServlet 注解

[英]use @WebServlet annotation in maven jetty plugin

I build an web application in my ecplise with maven plugin I want debug it in jetty.我使用 maven 插件在我的 ecplise 中构建了一个 Web 应用程序,我想在码头中对其进行调试。

this is my code:这是我的代码:

@WebServlet(name="Startup",value="/", urlPatterns = {}, loadOnStartup = 1)
public class Startup extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see Servlet#init(ServletConfig)
     */
    @Override
    public void init(ServletConfig config) throws ServletException {
        System.out.println("start up");
        QCloud.setupSDK();
    }

I don't know if it's your case but I faced similar issue with Jetty. 我不知道这是否是您的情况,但Jetty面临类似的问题。

When using annotations the web.xml file is not needed anymore, so if you have it then remove it (even if there are no servlets mapped inside) and it will make the trick. 使用注释时,不再需要web.xml文件,因此,如果有它,则将其删除(即使内部没有映射的servlet)也可以解决。

Also note that either value or urlPatterns are required attributes for @WebServlet annotation but you shouldn't use both at the same time. 还要注意,@ WebServlet注解的必需属性是valueurlPatterns ,但您不应同时使用两者。

This Github issue mentions that servlet API moved packages from javax.*<\/code> to jakarta.*<\/code> .这个 Github 问题提到 servlet API 将包从javax.*<\/code>移动到jakarta.*<\/code> 。 Only Jetty 11 and later changed to reading annotations from jakarta<\/code> .只有 Jetty 11 及以后改为从jakarta<\/code>读取注释。 Perhaps, your code uses the newer jakarta servlet API and older Jetty 9.也许,您的代码使用较新的 jakarta servlet API 和较旧的 Jetty 9。

https:\/\/github.com\/eclipse\/jetty.project\/issues\/5964#issuecomment-777083559<\/a> https:\/\/github.com\/eclipse\/jetty.project\/issues\/5964#issuecomment-777083559<\/a>

"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM