0

For some reason bootstrap webjars are not being copied into target, and for that reason they cannot be found.

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>

Resource handlers:

@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/");
}
}

Somewhere in my static resources

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

enter image description here

Nothing is generated into /target Any idea what am I missing? I spend few hours on this and also reached second page on google searches.

krzakov
  • 3,871
  • 11
  • 37
  • 52
  • That all seems like it should work. But it isn't quite consistent with what you need to do for Spring Boot. Check out: https://www.webjars.org/documentation#springboot – James Ward Aug 15 '18 at 04:50
  • @JamesWard I double checked with the linked you sent. Results are exactly the same. I also changed into `version agnostic` approach with new dependency, however it does exactly the same. What you mean by saying its not consistent? – krzakov Aug 15 '18 at 09:43
  • Remove the `WebConfiguration`, Spring Boot already takes care of all that and you are basically disabling parts of Spring Boot pautoconfiguration with that config. – M. Deinum Aug 15 '18 at 12:06

1 Answers1

2

I will answer my own question.

I would never tell that could be a problem but apparently @GetMapping annotation broke my UI. I still didn't figure it out what was the problem. I just found solution.

So I used Thymeleaf to resolve my views

@Controller
public class ViewController {

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

And apparently it clashes when I use traditional Restful controller

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

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

This single @GetMapping was breaking entire UI. What I had to do was simply add / in the mapping

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

And the whole thing magically started to work. Similar issue somewhere deep in the github: https://github.com/springfox/springfox/issues/1647

krzakov
  • 3,871
  • 11
  • 37
  • 52