0

由于某种原因,引导程序 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/");
}
}

在我静态的某个地方resources

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

在此处输入图像描述

什么都没有生成/target 任何想法我错过了什么?我花了几个小时在这上面,也到达了谷歌搜索的第二页。

4

1 回答 1

2

我会回答我自己的问题。

我永远不会说这可能是一个问题,但显然@GetMapping注释破坏了我的 UI。我仍然没有弄清楚是什么问题。我刚刚找到了解决方案。

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

@Controller
public class ViewController {

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

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

@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

于 2018-08-15T12:03:50.513 回答