Chvalov
@Chvalov

Ошибка доступа к статическим ресурсам SpringBoot, куда смотреть?

Spring boot 1.5.7
Получаю вот такую картину:
5a122e99d88f1858780511.png
@Configuration
@EnableWebMvc
public class MvcConfiguration extends WebMvcConfigurerAdapter {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry
                .addResourceHandler("/resources/**")
                .addResourceLocations("/resources/");
    }
}

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.
                authorizeRequests()
                .antMatchers("/").hasAnyRole("USER", "ADMIN")
                .antMatchers("/welcome").hasAnyRole("USER", "ADMIN")
                .antMatchers("/admin").hasRole("ADMIN")
                .and()
                .formLogin().loginPage("/login").defaultSuccessUrl("/welcome").failureUrl("/login?error")
                .usernameParameter("username").passwordParameter("password")
                .and().logout()
                .logoutSuccessUrl("/login?logout");
    }

Вот что творится в логах:
2017-11-20 03:22:36.740  WARN 11224 --- [nio-8080-exec-9] o.s.web.servlet.PageNotFound             : No mapping found for HTTP request with URI [/img/logo.png] in DispatcherServlet with name 'dispatcherServlet'
2017-11-20 03:22:36.740 DEBUG 11224 --- [nio-8080-exec-9] o.s.b.a.e.mvc.EndpointHandlerMapping     : Looking up handler method for path /error
2017-11-20 03:22:36.741 DEBUG 11224 --- [nio-8080-exec-9] o.s.b.a.e.mvc.EndpointHandlerMapping     : Did not find handler method for [/error]
2017-11-20 03:22:37.180 DEBUG 11224 --- [nio-8080-exec-4] o.s.b.a.e.mvc.EndpointHandlerMapping     : Looking up handler method for path /js/jquery.min.js
2017-11-20 03:22:37.182 DEBUG 11224 --- [nio-8080-exec-4] o.s.b.a.e.mvc.EndpointHandlerMapping     : Did not find handler method for [/js/jquery.min.js]
2017-11-20 03:22:37.182  WARN 11224 --- [nio-8080-exec-4] o.s.web.servlet.PageNotFound             : No mapping found for HTTP request with URI [/js/jquery.min.js] in DispatcherServlet with name 'dispatcherServlet'
2017-11-20 03:22:37.183 DEBUG 11224 --- [nio-8080-exec-4] o.s.b.a.e.mvc.EndpointHandlerMapping     : Looking up handler method for path /error
2017-11-20 03:22:37.184 DEBUG 11224 --- [nio-8080-exec-4] o.s.b.a.e.mvc.EndpointHandlerMapping     : Did not find handler method for [/error]
2017-11-20 03:22:37.274 DEBUG 11224 --- [io-8080-exec-10] o.s.b.a.e.mvc.EndpointHandlerMapping     : Looking up handler method for path /js/login.js
2017-11-20 03:22:37.276 DEBUG 11224 --- [io-8080-exec-10] o.s.b.a.e.mvc.EndpointHandlerMapping     : Did not find handler method for [/js/login.js]
2017-11-20 03:22:37.277  WARN 11224 --- [io-8080-exec-10] o.s.web.servlet.PageNotFound             : No mapping found for HTTP request with URI [/js/login.js] in DispatcherServlet with name 'dispatcherServlet'

5a122fcd58c79997474012.png
Ресурсы подключаю так:
<head>
    <title>Auth page</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" th:href="@{/css/bootstrap.min.css}" type="text/css" />
    <link rel="stylesheet" th:href="@{/css/bootstrap-grid.min.css}" type="text/css" />
    <link rel="stylesheet" th:href="@{/css/bootstrap-reboot.min.css}" type="text/css" />
    <link rel="stylesheet" th:href="@{/css/main.css}" type="text/css" />
    <link rel="stylesheet" th:href="@{/css/font-awesome.min.css}" type="text/css" />
    <link href='http://fonts.googleapis.com/css?family=Open+Sans:400,700,800' rel='stylesheet' type='text/css'/>
</head>
  • Вопрос задан
  • 2600 просмотров
Пригласить эксперта
Ответы на вопрос 1
zolt85
@zolt85
Программист
Все Вам верно Spring говорит. Попробуйте ссылки на ресурсы в html подключать как "@{/resources/css/bootstrap.min.css}". Либо хендлеры добавьте по-другому
@Configuration
@EnableWebMvc
public class MvcConfiguration extends WebMvcConfigurerAdapter {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry
                .addResourceHandler("/js/**")
                .addResourceLocations("/resources/js/");
        registry
                .addResourceHandler("/css/**")
                .addResourceLocations("/resources/css/");
    }
}
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
Bell Integrator Ульяновск
До 400 000 ₽
Bell Integrator Ижевск
До 400 000 ₽
Bell Integrator Хабаровск
До 400 000 ₽
29 мар. 2024, в 10:00
10000 руб./за проект
29 мар. 2024, в 09:59
750 руб./в час
29 мар. 2024, в 09:55
50000 руб./за проект