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>
  • Вопрос задан
  • 2762 просмотра
Пригласить эксперта
Ответы на вопрос 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/");
    }
}
Ответ написан
Ваш ответ на вопрос

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

Похожие вопросы
22 нояб. 2024, в 03:54
1500 руб./за проект
22 нояб. 2024, в 02:56
10000 руб./за проект
22 нояб. 2024, в 00:55
500 руб./за проект