当前位置:首页>维修大全>综合>

如何在spring-boot中自定义dispatchServlet的访问路径(springboot如何设置访问权限)

如何在spring-boot中自定义dispatchServlet的访问路径(springboot如何设置访问权限)

更新时间:2025-08-22 04:01:57

如何在spring-boot中自定义dispatchServlet的访问路径

在程序的主入口中定义dispatchRegistration

package com.lzl;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.boot.web.servlet.ServletComponentScan;

import org.springframework.boot.web.servlet.ServletRegistrationBean;

import org.springframework.context.annotation.Bean;

import org.springframework.web.servlet.DispatcherServlet;

import com.lzl.servlet.MyServlet;

@SpringBootApplication

public class SpringBootDemoApplication {

public static void main(String[] args) {

SpringApplication.run(SpringBootDemoApplication.class, args);

}

@Bean

public ServletRegistrationBean dispatcherRegistration(DispatcherServlet dispatcherServlet) {

ServletRegistrationBean reg = new ServletRegistrationBean(dispatcherServlet);

reg.getUrlMappings().clear();

reg.addUrlMappings("*.html");

reg.addUrlMappings("*.do");

return reg;

}

}

更多栏目