springboot 配置 servlet filter 2

springboot 配置 servlet filter 2

以配置Druid为例

Servlet

java 复制代码
@WebServlet(
        urlPatterns = "/druid/*",
        initParams = {
                @WebInitParam(name = "loginUsername", value = "admin"),// 登录用户名
                @WebInitParam(name = "loginPassword", value = "123456"),// 登录密码
                @WebInitParam(name = "resetEnable", value = "false"),// 禁用HTML页面上"Reset All"功能
                @WebInitParam(name = "deny", value = ""), // ip黑名单(deny优于allow),多个用,隔开
                @WebInitParam(name = "allow", value = "127.0.0.1")// IP白名单(没有配置或则为空,则允许访问所有),多个用,隔开
        })
public class DruidStatViewServlet extends StatViewServlet {

}

Filter

java 复制代码
@WebFilter(
        filterName = "druidWebStatFilter",
        urlPatterns = {"/*"},
        initParams = {
                @WebInitParam(name = "exclusions", value = "*.js,*.jpg,*.png,*.gif,*.ico,*.css,/druid/*")
        }
)
public class DruidStatFilter extends WebStatFilter {
}

Config

java 复制代码
@Configuration
@ServletComponentScan // 用于扫描所有的Servlet、filter、listener
public class DruidConfiguration {
    /**
     * 加载时读取指定的配置信息,前缀为spring.datasource.druid
     * @return
     */
    @Bean
    @ConfigurationProperties(prefix = "spring.datasource")
    public DataSource druidDataSource() {
        return new DruidDataSource();
    }
}
相关推荐
paopaokaka_luck15 小时前
基于springboot3+vue3的智能文库平台(AI智能搜索、AI智能汇总、实时在线状态展示、多格式文档预览与富文本编辑、Echarts图形化分析)
前端·网络·spring boot·网络协议·echarts
zzzll111116 小时前
Spring Boot 入门指南:从零开始构建 Java Web 应用
java·前端·spring boot
热心市民lcj21 小时前
Spring Boot 整合 Caffeine 本地缓存实战
spring boot·后端·缓存
天丁o1 天前
Spring Boot + MyBatis Plus 考勤日报统计报表:打卡记录聚合、异常分类和明细下钻 Demo
spring boot·mybatis plus·企业数字化·考勤系统·报表统计
智_永无止境1 天前
Spring Boot 集成 OnlyOffice
java·spring boot·后端
Devin~Y1 天前
从本地生活电商到 AI RAG:互联网大厂 Java 面试场景完整实战
java·spring boot·redis·elasticsearch·spring cloud·kafka·rag
米码收割机1 天前
SA508-3钢回火焊道焊接温度场数值模拟(模拟图+论文)
spring boot·express·宠物
米码收割机1 天前
【项目】spring boot+vue3 宠物领养系统(源码+文档)【独一无二】
java·spring boot·宠物
momo1 天前
Java+WebAI黑马知识点
java·spring boot·mybatis
就改了2 天前
Mybatis快速入门大全(详细版)
java·spring boot·mybatis