1

According to the docs Spring Boot registers src/main/resources/static, src/main/resources/public, src/main/resources/resources, etc. for static resources locations.

I got

src/main/resources
    -static
        -js
           -stomp.js

and in the html(placed in templates folder):

<script type="text/javascript"  th:src="@{/js/stomp.js}"></script>

but I got 404 for the script(GET http://localhost:8080/js/stomp.js 404 (Not Found) ). What I do wrong?

I also tried

<script type="text/javascript"  src="../static/js/stomp.js"></script>

and

<script type="text/javascript"  src="/js/stomp.js"></script>

with the same result.

My mvc configuration(just one view-controller):

@EnableWebMvc
@ComponentScan(basePackages = {"controller"})
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
      registry.addViewController("/sock").setViewName("/index");
    }
}

and i got

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

in the POM.

1

1 Answer 1

7

Explicit declaration of @EnableWebMvc disables Spring Boot's autoconfiguration for Web MVC.

Either remove it from your WebMvcConfig to enable autoconfiguration, or add resource handlers for static content manually in addResourceHandlers() if you don't want to enable autoconfiguration.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.