public class KeepaliveSupport extends WebMvcConfigureConfig { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/keepalive/**").addResourceLocations(KeepAliveConfig.keepaliveLocations); super.addResourceHandlers(registry); public void addInterceptors(InterceptorRegistry registry) { super.addInterceptors(registry);

2.KeepAliveConfig.keepaliveLocations从配置文件中读取值

@Configuration
@Component
@Data
public class KeepAliveConfig {
    public static String keepaliveLocations;
    @Value("${system.keepalive.locations}")
    public void setKeepaliveLocations(String keepaliveLocations){
        KeepAliveConfig.keepaliveLocations=keepaliveLocations;

3.system.keepalive.locations在配置文件中配置的地址如下:

system.keepalive.locations=file:/var/java-app/comments-component/

参考文档:

https://blog.csdn.net/ajklaclk/article/details/80804137

https://www.jianshu.com/p/54e0ca450f88

https://blog.csdn.net/ljj_9/article/details/79650008

https://blog.csdn.net/weixin_40050532/article/details/80799708

可以通过配置addResourceHandler和addResourceLocations来读取本地资源文件1.@Configurationpublic class KeepaliveSupport extends WebMvcConfigureConfig { @Override public void addResourceHandlers(ResourceHand...
拦截器类 需要两个配合使用这里只有一个 @Configuration public class ServletContextConfig extends WebMvcConfigurerAdapter { public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/"); registry.addResourceHandler("/templates/**").addResourceLocations("classpath:/templates/"); super.addResourceHandlers(registry); @Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(new HandlerMyInterceptorAdapter()).addPathPatterns("/**") .excludePathPatterns("/") // .excludePathPatterns("/expressions/getExpressionsList") .excludePathPatterns("/loginInfo/getCordByIsPhone") .excludePathPatterns("/loginInfo/login11") //token失效跳轉 .excludePathPatterns("/loginInfo/insertLoginInfo") //注册 .excludePathPatterns("/loginInfo/login") //登录 .excludePathPatterns("/upload") //上传文件 .excludePathPatterns("/uploadListen") //上传文件 .excludePathPatterns("/admin/user/goLogin") //后台跳转登录 .excludePathPatterns("/admin/user/login") //后台登录 .excludePathPatterns("/loginInfo/getLoginInfo") //忘记密码 .excludePathPatterns("/loginInfo/getCord") //短信验证码 .excludePathPatterns("/loginInfo/getIsLoginInfo") //判断验证码&&登录 .excludePathPatterns("/loginInfo/getIsLoginInfo1") //判断验证码 .excludePathPatterns("/loginInfo/setPassWord") //设置密码 @Override public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) { configurer.enable(); @Component public class HandlerMyInterceptorAdapter implements HandlerInterceptor { @Autowired private HeartbeatServiceImpl heartbeatService; @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException { String url = request.getRequestURI(); if (url.contains("admin")) { User user = (User) request.getSession().getAttribute("user"); try { if (user.equals(null)) { response.sendRedirect(serverConfig.SERVER + "admin/user/goLogin"); return false; } else { return true; }catch (Exception e){ response.sendRedirect(serverConfig.SERVER + "admin/user/goLogin"); return false; }else { String token = request.getHeader("token"); if (token != null) { Jedis jedis = new Jedis(com.sevenSteps.util.RedisConfig.HOST, RedisConfig.PORT); String s = jedis.get(token); if(token.equals(s)) { heartbeatService = SpringUtil.getBean(HeartbeatServiceImpl.class); return heartbeatService.setOutDate(token); }else { response.sendRedirect(serverConfig.SERVER + "loginInfo/login11"); return true; }else { response.sendRedirect(serverConfig.SERVER + "loginInfo/login11"); return true; @Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object o, ModelAndView modelAndView) throws Exception { @Override public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
springboot+nginx访问文件或重写addResourceHandlers映射文件路径 每天多学一点点~ 最近跳槽了去新公司,清闲了两周,心里面有点慌,遂研究了点新东西~ 话不多说,这就开始吧… 文章目录springboot+nginx访问文件或重写addResourceHandlers映射文件路径1.序言2.addResourceHandlers方法3.测试映射文件路径4.nginx配...
场景:部署的Springboot项目,打成jar包,需要通过url直接访问jar外部路径的资源,本人的Springboot为2.1.11.RELEASE。 一、配置WebMvcConfigurer,设置url访问静态资源映射 @Configuration public class WebMvcConfig implements WebMvcConfigurer {
自定义资源映射addResourceHandlers: 在springboot,我们可以通过重写addResourceHandlers方法来映射静态资源目录; 具体做法:编写类继承WebMvcConfigurerAdapter类,重写该类的addResourceHandlers方法;其addResourceHandler指向映射路径,addResourceLocations指向资源文件路径;资...
开始我是这样设置的 registry.addResourceHandler("/upload/**").addResourceLocations("file:" + path); 完整代码如下图: path对应的路径在 yml 文件设置,如下图 然后项目启动后,通过在浏览器直接访问文件的地址(例如:http://localhost:8090/app...
@Configuration public class MyWebMVCConfig implements WebMvcConfigurer { @Value("${file.location}") // D:/test/ String filelocation; // 这两个是路径 @Value("${file.path}") // /file/** String
import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import org.springframework.web.se...
您可以通过以下方式获取Spring Boot已配置的日志级别: 1. 在application.properties或application.yml文件查找logging.level属性,该属性指定了应用程序每个包的日志级别。 2. 在运行应用程序时,使用--debug或--trace选项启动应用程序,这将显示应用程序所有日志记录的详细信息,包括日志级别。 3. 在代码使用org.slf4j.Logger接口记录日志,并在日志记录语句指定日志级别。例如,logger.debug("Debug message")将记录调试级别的日志消息。