【问题标题】:Spring Boot with themeleaf not able to access css on HTML file带有主题的 Spring Boot 无法访问 HTML 文件上的 css
【发布时间】:2017-12-27 22:54:04
【问题描述】:

技术:带有主题的 Spring Boot

我正在尝试使用以下代码访问我的 HTML 上 src/main/resources/assets/vendor/bootstrap/css/bootstrap.css 下的 css 文件:

但它没有加载。

文件夹结构:

资源

--->资产

----->供应商

--------->引导

------------>css

--------------->bootstrap.css

--->代码

有人可以帮我吗?

【问题讨论】:

  • 请添加您的代码。
  • @sirandy: HTML 代码

标签: spring spring-boot


【解决方案1】:

来自我的工作项目。资源位于 resources/static/js/script.js 下。我正在从 js/script.js 之类的 html 访问它。没有任何问题。可能您缺少静态文件夹。如果您使用的是 Spring Security,则需要使资源可用。

【讨论】:

  • 是的,我正在使用 Spring Security。我将所有文件夹移动到资源下的静态文件夹。仍然没有加载。它说样式表无法加载 localhost:9000/assets/vendor/bootstrap/css/bootstrap.css
【解决方案2】:

这是我的 spring 安全配置,

    http.
             csrf().disable()
            .authorizeRequests()
            .antMatchers("/home/**", "/**", "/css/**", "/js/**", "/fonts/**", "/images/**", "/public/rest/**","/login*","/signin/**","/signup/**").permitAll()
            .antMatchers("/property/**").authenticated()
            .antMatchers("/welcome/**").authenticated()
            .and()
            .formLogin().loginPage("/login").permitAll()
            .and().httpBasic().disable();

只需要这条线,

  .antMatchers("/home/**", "/**", "/css/**", "/js/**", "/fonts/**", "/images/**", "/public/rest/**","/login*","/signin/**","/signup/**").permitAll()

但是,我建议先禁用安全性并检查一切是否正常。如果可行,则重新启用安全性并尝试按所示配置它。

【讨论】:

    猜你喜欢
    • 2020-04-03
    • 2014-02-02
    • 2019-05-24
    • 1970-01-01
    • 2021-03-10
    • 1970-01-01
    • 2021-12-15
    • 2022-01-25
    • 2015-09-27
    相关资源
    最近更新 更多