Spring MVC + Maven + Bootstrap Problem

Asked

Viewed 269 times

0

Good morning. I’m trying to put bootstrap on the index of my application but I’m not getting it, index does not read CSS. I searched on the Internet and from what I understood, css should be within the following structure, src/main/webapp/Resources.css/

<!-- Bootstrap core CSS -->
<link href="/resources.css/bootstrap.min.css" rel="stylesheet">

The structure is like this; inserir a descrição da imagem aqui

  • 1

    Has the answer helped you to resolve the doubt? It is possible to accept it now?

1 answer

1

You need to configure Spring to serve your static resources. This can be done programmatically or via XML.

Class of Java configuration

@Configuration
public class SpringConfig extends WebMvcConfigurerAdapter {  

   ...

   @Override
   public void addResourceHandlers(ResourceHandlerRegistry registry) {
       registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
   }

   @Override
   public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
       configurer.enable();
   }
}

Servlet.xml

<mvc:resources mapping="/resources/**" location="/resources/"/>
  • thanks Murillo for the return, have some example of configuration programmatically ?

  • This is the example with title Java configuration class

  • Okay, I get it, thank you so much for your help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.