springBoot 2.7.x版本代码配置静态资源映射不生效
时间: 2024-05-05 10:17:19 浏览: 11
如果您的SpringBoot 2.7.x版本代码配置静态资源映射不生效,可能需要检查以下几个方面:
1. 确认静态资源文件放置位置是否正确,一般在src/main/resources/static目录下。
2. 确认静态资源文件是否正确引用,例如在html文件中正确引用css、js等文件。
3. 确认静态资源映射是否正确配置,例如在application.properties或application.yml文件中正确配置spring.resources.static-locations属性,示例如下:
application.properties:
```
spring.resources.static-locations=classpath:/static/
```
application.yml:
```
spring:
resources:
static-locations: classpath:/static/
```
4. 如果仍然无法生效,可能需要检查是否存在其他配置文件或代码覆盖了静态资源映射配置,需要进行排查。
相关问题
SpringBoot2.x引入静态资源报错No mapping for GET XXXX的解决办法以及原理
当我们在SpringBoot2.x中引入静态资源时,有时候会出现No mapping for GET XXXX的报错。这是因为SpringBoot2.x中的静态资源映射规则与之前的版本略有不同。
解决办法:
1.将静态资源放置在默认的/static、/public或/resources目录下。
2.在application.properties或application.yml中添加静态资源映射规则。
application.properties:
```
spring.mvc.static-path-pattern=/static/**
spring.resources.static-locations=classpath:/static/
```
application.yml:
```
spring:
mvc:
static-path-pattern: /static/**
resources:
static-locations: classpath:/static/
```
原理:
SpringBoot2.x中默认的静态资源映射规则是/static、/public或/resources目录下的所有静态资源都会被映射为/路径下的资源,如/static/js/app.js会被映射为/js/app.js。
而如果我们希望自定义静态资源映射规则,则需要在application.properties或application.yml中添加对应的配置项。spring.mvc.static-path-pattern用于设置静态资源的映射规则,spring.resources.static-locations用于设置静态资源的存放位置。
springboot2.x javacv实现 rtsp 拉流
使用Spring Boot 2.x结合JavaCV实现RTSP拉流需要进行以下步骤:
1. 首先,在Spring Boot的pom.xml中添加JavaCV的依赖:
```
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv</artifactId>
<version>1.5.3</version>
</dependency>
```
2. 创建一个Spring Boot的Controller类,用于处理请求:
```java
@RestController
public class RTSPController {
@GetMapping("/play")
public void playRTSP() throws FrameGrabber.Exception {
String rtspUrl = "rtsp://example.com/stream"; // RTSP流的URL地址
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(rtspUrl);
grabber.start();
// 读取帧
Frame frame;
while ((frame = grabber.grab()) != null) {
// 处理帧的逻辑
// ...
}
grabber.stop();
}
}
```
3. 在上述代码中,首先定义了一个RTSP流的URL地址,然后创建了一个FFmpegFrameGrabber对象来获取帧。通过调用`start()`方法启动流的读取,然后在一个循环中使用`grab()`方法来逐帧读取流。可以在循环中添加逻辑来处理每一帧的数据。
4. 最后,使用Spring Boot的`@GetMapping`注解将该方法映射到一个URL路径上(在上面的例子中是`/play`),可以通过向该URL发起GET请求来启动RTSP流的拉取。
以上就是使用Spring Boot 2.x和JavaCV实现RTSP拉流的简单示例。请注意,该示例仅包含了获取帧的逻辑,具体的处理逻辑需要根据实际需求进行扩展。