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