gpt4 book ai didi

java - Spring boot webjars未生成,Http 406返回

转载 作者:行者123 更新时间:2023-12-02 01:59:27 25 4
gpt4 key购买 nike

由于某种原因, Bootstrap webjar 没有被复制到目标中,因此无法找到它们。

pom.xml

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
</parent>

...

<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>4.1.3</version>
</dependency>

资源处理程序:

@Configuration
@EnableWebMvc
public class WebConfiguration implements WebMvcConfigurer {

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/WEB-INF/resources/*");
registry.addResourceHandler("/resources/").addResourceLocations("/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}

在我的静态资源中的某个地方

...
<script src="webjars/bootstrap/4.1.3/js/bootstrap.min.js"></script>
...

enter image description here

/target 中没有生成任何内容知道我错过了什么吗?我花了几个小时在这上面,并且在谷歌搜索上也到达了第二页。

最佳答案

我会回答我自己的问题。

我永远不会说这可能是一个问题,但显然 @GetMapping 注释破坏了我的 UI。我还是没明白问题出在哪里。我刚刚找到解决方案。

所以我使用Thymeleaf来解决我的观点

@Controller
public class ViewController {

@GetMapping("/")
public String home() {
return "/home";
}
}

显然,当我使用传统的 Restful Controller 时,它会发生冲突

@RestController(value = "/face-detection")
public class FaceDetectController {

@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) {
...

这个@GetMapping破坏了整个UI。我所要做的只是在映射中添加 /

@GetMapping(value ="/", produces = MediaType.APPLICATION_JSON_VALUE)

整个事情神奇地开始发挥作用。类似的问题在 github 深处: https://github.com/springfox/springfox/issues/1647

关于java - Spring boot webjars未生成,Http 406返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51852015/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com