public class ResponseHeaderInterceptor implements Interceptor { @Override public void intercept(Invocation inv) { inv.invoke(); HttpServletRequest request = inv.getController().getRequest(); HttpServletResponse response = inv.getController().getResponse(); response.setHeader("Content-Security-Policy", "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data:<192.168.1.200/sfiles>; object-src 'self' blob:;"); } } 报错:Refused to load the image 'blob:<URL>' because it violates the following Content Security Policy directive: "img-src 'self' <URL>".
时间: 2024-03-12 16:44:26 浏览: 25
这个错误提示意味着你的 Content Security Policy 指令不允许加载来自指定 URL 的图片资源。
解决这个问题的方法可能是将你想要加载的图片资源的 URL 添加到 Content Security Policy 的白名单中。你可以在 img-src 指令中添加白名单,例如:
```
img-src 'self' data:<192.168.1.200/sfiles> blob:;
```
这将允许加载来自 'self'、data URL 和 blob URL 的图片资源,其中 data URL 是用于嵌入图片数据的一种特殊 URL。
另外,你还需要确保你的图片资源确实存储在指定的 URL 上,并且可以从这个 URL 加载。如果这个 URL 不可用或者图片资源已经被删除,则会导致加载失败并出现类似的错误提示。
相关问题
public class ResponseHeaderInterceptor implements Interceptor { @Override public void intercept(Invocation inv) { inv.invoke(); HttpServletRequest request = inv.getController().getRequest(); HttpServletResponse response = inv.getController().getResponse(); response.setHeader("Content-Security-Policy", "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; object-src 'self'"); } } 无法加载HBIM模型
如果你在 JFinal 中使用 ResponseHeaderInterceptor 设置 CSP 策略时无法加载 Hbim 模型,那么可能是因为 CSP 策略中没有包含允许加载 Hbim 模型的来源。
你可以尝试添加 "object-src" 指令,允许从 Blob URL 加载数据。以下是一个示例:
```java
public class ResponseHeaderInterceptor implements Interceptor {
@Override
public void intercept(Invocation inv) {
inv.invoke();
HttpServletRequest request = inv.getController().getRequest();
HttpServletResponse response = inv.getController().getResponse();
response.setHeader("Content-Security-Policy", "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; object-src 'self' blob:;");
}
}
```
上述 CSP 策略指定了允许从 Blob URL 加载对象(包括 Hbim 模型),其他的来源和之前的示例代码相同。
需要注意的是,CSP 策略语法和浏览器支持程度可能因浏览器版本而异,因此你需要根据实际情况调整 CSP 策略。同时,加载 Hbim 模型的方式可能因不同的模型库而异,你需要查看所使用的模型库的文档来确定正确的加载方式。
@Order(99) @Component @Intercepts({@Signature(type = Executor.class, method = "close", args = {})}) public class ConnectionInterceptor implements Interceptor { @Override public Object intercept(Invocation invocation) throws Throwable { System.out.println("ConnectionInterceptor.intercept..."); Object target = invocation.getTarget(); if (target instanceof Executor) { Connection connection = ((Executor) target).getTransaction().getConnection(); if (connection != null && !connection.isClosed()) { connection.close(); } } return invocation.proceed(); } @Override public Object plugin(Object target) { return Plugin.wrap(target, this); } @Override public void setProperties(Properties properties) { } }报错找不到close方法
根据您提供的代码和错误信息,您的插件类ConnectionInterceptor中使用了Executor接口的close()方法,但是MyBatis在执行时找不到该方法。这可能是因为您使用的MyBatis版本和Executor接口的版本不匹配,建议检查版本是否正确。
此外,建议将您的插件类ConnectionInterceptor注册到MyBatis中,这可以通过在MyBatis配置文件中添加以下配置来实现:
```
<plugins>
<plugin interceptor="你的插件类路径" />
</plugins>
```
如果您使用的是Spring Boot,您可以在application.properties或application.yml中添加以下配置来注册插件:
```
mybatis.configuration.interceptor.classes=你的插件类路径
```
请注意,如果您使用了多个插件,请按照您希望它们执行的顺序指定它们的顺序。可以通过在插件类上添加@Order注解来指定插件的执行顺序,数字越小,插件越先执行。
如果以上方法无法解决您的问题,请提供更多的错误信息和代码细节,以便更好地帮助您解决问题。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)