mercredi 25 février 2015

Spring 4 - unable to deliver static content (bootstrap)

I'm trying to serve some static content (css and js files) in a Spring Boot application. Accordingly to this guide (http://ift.tt/1zHGMP4), all the contents in the src/main/resources/[static-public] are automatically added to the classpath, and so available. Unfortunately, I manage to load the html page, but I don't understand how to load the css files.


My directory structure is


Project structure


My main Application class is



@Configuration
@EnableWebMvc
@ComponentScan(basePackages={"controller"})
@EnableAutoConfiguration
public class Main extends WebMvcConfigurerAdapter {
public static void main(String[] args) {
SpringApplication.run(Main.class, args);
}

}


and my index.html header looks like



<!-- JQuery -->
<script src="lib/jquery.min.js"></script>
<script src="lib/d3.js" charset="utf-8"></script>
<script src="lib/d3.min.js" charset="utf-8"></script>
<script src="lib/jsnetworkx.js"></script>
<link rel="stylesheet" type="text/css" th:href="@{/lib/bootstrap/css/bootstrap.min.css}" href="../lib/bootstrap/css/bootstrap.min.css" />
<!-- <link rel="stylesheet" href="lib/bootstrap/css/bootstrap.min.css" /> -->
<link rel="stylesheet" type="text/css" th:href="@{/lib/bootstrap/css/bootstrap-theme.min.css}" href="../lib/bootstrap/css/bootstrap-theme.min.css" />
<!-- <link rel="stylesheet" href="lib/bootstrap/css/bootstrap-theme.min.css" /> -->
<script src="lib/bootstrap/js/bootstrap.min.js"></script>

<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="http://ift.tt/1xwklwE"></script>
<script src="http://ift.tt/1qIredN"></script>
<![endif]-->
</head>


Thanks a lot


Aucun commentaire:

Enregistrer un commentaire