Cannot import org.h2.server.web.WebServlet

不想你离开。 提交于 2019-12-03 07:00:17

Shouldn't h2 be a compile (instead of runtime) dependency?

I had the same problem, probably running the same example. Had the correct maven pom.xml dependency but for some reason had to download the h2 driver jar directly from Maven. Then the code above worked. Taking away "runtime" element will default to compile.

    <!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>1.4.192</version>
    </dependency>

Just remove runtime form your h2 dependency and everything will be fine

FYI, 'runtime' scope is default by design. The reason is mentioned in the following Github page. (I leave it to you to decide) https://github.com/spring-projects/spring-boot/issues/16509

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!