Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't load styles #6

Open
zvmv opened this issue Jul 20, 2023 · 0 comments
Open

Can't load styles #6

zvmv opened this issue Jul 20, 2023 · 0 comments

Comments

@zvmv
Copy link

zvmv commented Jul 20, 2023

I Try to load style from my resources folder (/resources/static/css/styles.css) but get 404.

@Configuration
@EnableWebMvc
public class PugTemplateConfiguration {
    @Bean
    public SpringTemplateLoader templateLoader() {
        SpringTemplateLoader templateLoader
                = new SpringTemplateLoader();
        templateLoader.setTemplateLoaderPath("classpath:/templates/");
        templateLoader.setEncoding("UTF-8");
        templateLoader.setSuffix(".pug");
        return templateLoader;
    }
    @Bean
    public PugConfiguration pugConfiguration() {
        PugConfiguration configuration = new PugConfiguration();
        configuration.setCaching(false);
        configuration.setTemplateLoader(templateLoader());
        return configuration;
    }
    @Bean
    public ViewResolver viewResolver() {
        PugViewResolver viewResolver = new PugViewResolver();
        viewResolver.setConfiguration(pugConfiguration());
        return viewResolver;
    }
}

templates/index.pug

doctype html
html
  head
    meta(charset="UTF-8")
    link(rel="stylesheet" type="text/css" href="css/style.css")
    title document title
  body
    p hello, world!

styles located in resources/static/css/styles.css, in target folder I can see it in /static/css/styles.css

spring log:

DEBUG org.springframework.web.servlet.DispatcherServlet : GET "/css/style.css", parameters={} 
WARN org.springframework.web.servlet.PageNotFound : No mapping for GET /css/style.css 
DEBUG org.springframework.web.servlet.DispatcherServlet : Completed 404 NOT_FOUND

I tried to move style.css to 'templates' folder, but it did not help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant