Naveen
Naveen

Reputation: 5

Spring Boot with themeleaf not able to access css on HTML file

Technology : Spring Boot with themeleaf

I'm trying to access the css file placed under src/main/resources/assets/vendor/bootstrap/css/bootstrap.css on my HTML using the following code:

But it is not loading.

Folder Structure :

Resources

--->assets

------>vendor

--------->bootstrap

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

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

--->code

Can any one help me in this?

Upvotes: 0

Views: 347

Answers (2)

Imran
Imran

Reputation: 1902

Here is my spring security config,

    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();

Simply you need this line,

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

But, I would suggest to disable security first and check if everything is working. If that works, then reenable security and try to configure it like shown.

Upvotes: 1

Imran
Imran

Reputation: 1902

From my working project. The resources is under resources/static/js/script.js. And I am accessing it from html like js/script.js. No issue. Probably you are missing static folder. And if you are using spring security, you need to make the resources available.

enter image description here

Upvotes: 0

Related Questions