此jar其中包含Tomcat、servlet等
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
或者
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
或者
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
java.lang.IllegalStateException: Cannot convert value of type 'com.springboot.conf.DruidStatViewServlet' to required type 'javax.servlet.Servlet' for property 'servlet': no matching editors or conversion strategy found
或者
Caused by: java.lang.ClassNotFoundException: org.springframework.web.context.WebApplicationContext
俺不晓得,据错误提示似乎是缺少相对应的servlet、filter、listen等属性
待俺寻的原因......
此方案有点憋屈,但是问题暂时解决
@WebServlet(urlPatterns = "/druid/*", initParams = { @WebInitParam(name = "allow", value = "127.0.0.1"), // IP白名单 (没有配置或者为空,则允许所有访问)
@WebInitParam(name = "deny", value = "192.168.0.1"), // IP黑名单 (存在共同时,deny优先于allow)
@WebInitParam(name = "loginUsername", value = "admin"), // 用户名
@WebInitParam(name = "loginPassword", value = "admin"), // 密码
@WebInitParam(name = "resetEnable", value = "true")// 禁用HTML页面上的“Reset All”功能
})
public abstract class DruidStatViewServlet extends StatViewServlet implements Servlet {
// 不需要实现接口中的方法,直接abstract抽象吧
}
@WebFilter(filterName = "druidWebStatFilter", urlPatterns = "/*", initParams = { @WebInitParam(name = "exclusions", value = "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*") })
public abstract class DruidStatFilter extends WebStatFilter implements Filter {
// 不需要实现接口中的方法,直接abstract抽象吧
}
俺用的jar
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!-- 排除内置容器,导出war供外部容器运行 -->
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>