java springboot + Dataway 导致默认静态文件访问失效 404

文章描述了在Springboot应用中集成Dataway后遇到的静态文件404问题。问题在于Dataway的拦截机制默认拦截了所有请求。通过修改注解@EnableHasorWeb的配置,限制其拦截路径为特定接口,解决了静态资源无法访问的问题。作者已提供了解决方案并分析了可能的内部处理逻辑。
摘要由CSDN通过智能技术生成

Springboot 集成 Dataway 导致 静态文件无法访问

问题描述

在使用 Springboot 集成 Dataway 时 由于安全性,和实现统一登录,自定义了登录和首页。
1. 直接访问 :http://localhost:8080/interface-ui/#/ 是可以进去页面
2. 访问:http://localhost:8080/index.html 404;并且所有的静态资源都无法访问。全部404

处理方案

// 在Dataway 提供的注解上 增加@EnableHasorWeb(path = {"/interface-ui/*","/api/*"})指定的拦截目标,否则将拦截所有请求。
// 有@EnableHasorWeb
//改为 @EnableHasorWeb(path = {"/interface-ui/*","/api/*"})
@EnableHasorWeb(path = {"/interface-ui/*","/api/*"})

问题查找

注:该问题目前没有找到Dataway最终处理拦截的地方,后半部分属于推测
由:EnableHasorWeb 源码可查到

@Target({ElementType.TYPE})
@Import({WebHasorConfiguration.class})
public @interface EnableHasorWeb {
	// 默认拦截所有请求,进行dataway 自身处理,包括但不限于重定向,转发等。。
    String[] path() default {"/*"};

    int order() default 0;

    WorkAt at() default WorkAt.Controller;
}

进入 WebHasorConfiguration类
由于知识体系问题,看到这只能猜测,此处将设置的拦截地址做了一个运行时过滤,并进行了自定义业务的处理,但是知识欠缺并不知道,接下来如何找到具体做拦截的类。但是根据我们的猜测已经足以处理该问题。就是只让dataway 拦截他自己的业务,其他的请求,不让他管


    @Bean
    @ConditionalOnWebApplication
    @ConditionalOnClass(
        name = {"net.hasor.web.startup.RuntimeListener"}
    )
    public Object addController(RequestMappingHandlerMapping requestMappingHandlerMapping) throws Exception {
        Objects.requireNonNull(this.appContext, "AppContext is not inject.");
        RuntimeFilter runtimeFilter = new RuntimeFilter(this.appContext);
        String[] filterPath = evalFilterPath(this.filterPath);
        switch(this.filterWorkAt) {
        case Filter:
            FilterRegistrationBean<Filter> filterBean = new FilterRegistrationBean(runtimeFilter, new ServletRegistrationBean[0]);
            filterBean.setUrlPatterns(Arrays.asList(filterPath));
            filterBean.setOrder(this.filterOrder);
            filterBean.setName(RuntimeFilter.class.getName());
            return filterBean;
        case Controller:
            RuntimeFilter2Controller handler = new RuntimeFilter2Controller(runtimeFilter, this.appContext);
            Method handlerMethod = RuntimeFilter2Controller.class.getMethod("doHandler", HttpServletRequest.class, HttpServletResponse.class);
            RequestMappingInfo info = RequestMappingInfo.paths(filterPath).methods(RequestMethod.values()).build();
            requestMappingHandlerMapping.registerMapping(info, handler, handlerMethod);
        default:
            return new Object();
        }
    }

使用版本

Dataway

 <!--整合dataway-->
        <dependency>
            <groupId>net.hasor</groupId>
            <artifactId>hasor-spring</artifactId>
            <version>4.2.5</version>
        </dependency>
        <dependency>
            <groupId>net.hasor</groupId>
            <artifactId>hasor-dataway</artifactId>
            <version>4.2.5</version>
        </dependency>
        <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.0</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

springboot: 2.5.0

希望 知道具体错误原因的兄台,指点一下。感谢感谢,

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值