【问题标题】:use @WebServlet annotation in maven jetty plugin在 maven jetty 插件中使用 @WebServlet 注解
【发布时间】:2017-11-28 14:58:20
【问题描述】:

我使用 maven 插件在我的 ecplise 中构建了一个 Web 应用程序 我想在码头调试它。

这是我的代码:

@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();
    }

这是 pom:

<plugin>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>9.3.0.M2</version>

            <configuration>
                <stopPort>8889</stopPort>
                <useTestClasspath>false</useTestClasspath>
                <webAppConfig>
                    <contextPath>/${project.name}</contextPath>
                </webAppConfig>

            </configuration>
        </plugin>

当我启动码头服务器时。没有错误显示。我可以看到索引页。 但我无法访问我的 servlet。似乎 servlet 没有使用码头服务器进行初始化。 然后我建立了一个战争并将其放入 tomcat 服务器的 webapps 中。 一切正常,servlet初始化成功,有人知道为什么吗?

【问题讨论】:

  • 不要使用代码图像。请发布您的实际代码。
  • 如果我删除注释中的 ,value="/" 。它不能正常工作。
  • 不要使用不稳定的 Jetty 版本。 9.3.0.M2 是里程碑/alpha/beta 版本。使用稳定的发布版本,例如9.4.6.v20170531

标签: java eclipse maven servlets jetty


【解决方案1】:

我不知道是不是你的情况,但我遇到了与 Jetty 类似的问题。

当使用注解时,不再需要 web.xml 文件,所以如果你有它,然后删除它(即使里面没有映射 servlet),它就会成功。 p>

另请注意,valueurlPatterns@WebServlet的必需属性> 注释,但您不应该同时使用两者。

【讨论】:

    猜你喜欢
    • 2011-11-13
    • 2015-08-19
    • 2011-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-17
    • 2013-12-09
    • 2014-08-20
    相关资源
    最近更新 更多