我试图在Spring应用程序中提供一些静态内容(css和js文件)。因此,对于本指南(http://spring.io/blog/2013/12/19/serving-static-web-content-with-spring-boot),src/main/resources/static中的所有内容都会自动添加到类路径中,因此是可用的。不幸的是,我成功地加载了html页面,但是我不明白如何加载css文件。
我的目录结构是

我的主要应用程序类是
@Configuration
@EnableWebMvc
@ComponentScan(basePackages={"controller"})
@EnableAutoConfiguration
public class Main extends WebMvcConfigurerAdapter {
public static void main(String[] args) {
SpringApplication.run(Main.class, args);
}
}我的index.html头看起来就像
<!-- 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="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>非常感谢
发布于 2015-02-25 15:11:38
如果您是@EnableWebMvc,那么关闭所有的启动默认MVC配置。只要把它移开。
https://stackoverflow.com/questions/28721893
复制相似问题