Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 弹簧靴&x2B;百里香叶+;webjars引导程序4_Spring_Spring Boot_Thymeleaf_Twitter Bootstrap 4_Webjars - Fatal编程技术网

Spring 弹簧靴&x2B;百里香叶+;webjars引导程序4

Spring 弹簧靴&x2B;百里香叶+;webjars引导程序4,spring,spring-boot,thymeleaf,twitter-bootstrap-4,webjars,Spring,Spring Boot,Thymeleaf,Twitter Bootstrap 4,Webjars,我正在尝试使用Thymeleaf将引导添加到我的Spring Boot项目中 index.html <!DOCTYPE html > <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head th:replace="fragments/header :: header"> </head> <body> <div th:replace="@{'views/' + ${co

我正在尝试使用Thymeleaf将引导添加到我的Spring Boot项目中

index.html

<!DOCTYPE html >
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="fragments/header :: header"> </head>
<body>

<div th:replace="@{'views/' + ${content}} :: ${content}"></div>

<div lang="en" th:replace="fragments/footer :: footer"> </div>
</body>
</html>
样式不应用于页面,引发错误: 在jquery、bootstrap和popper中

我怎样才能解决这个问题

谢谢。

如果您在pom.xml中使用依赖项,那么您可能应该在
webjars/…
之前添加斜杠
/
,并将属性
rel=“stylesheet”
保留在header.html中:

<link rel="stylesheet" th:href="@{/webjars/bootstrap/4.0.0-1/css/bootstrap.min.css} "/>


另外,请尝试在不使用
MvcConfig
配置类的情况下运行它。

为了使我获得的webjars定位器更容易:

 <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>bootstrap</artifactId>
        <version>4.0.0-2</version>
    </dependency>
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>webjars-locator</artifactId>
        <version>0.30</version>
    </dependency>

org.webjars
独自创立
4.0.0-2
org.webjars
webjars定位器
0.30
在我的页面的最后,我写了:

<script th:src="@{/webjars/jquery/jquery.min.js}"></script>
<script th:src="@{/webjars/popper.js/umd/popper.min.js}"></script>
<script th:src="@{/webjars/bootstrap/js/bootstrap.min.js}"></script>


我没有在Spring boot中使用任何其他设置。

在Spring boot中,Webjar是自动配置的。不需要添加任何处理程序或其他配置。运行应用程序时(无任何配置),可以看到如下日志:

... Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
因此,删除
MvcConfig
类可能会解决问题。

事实上,我的Spring Boot应用程序与您的类似(但没有该配置文件),并且工作得非常好。当我将您的配置添加到我的应用程序时,WebJars不再工作了

您还可以通过以下方式添加webjars依赖项来修复此问题

   <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>bootstrap</artifactId>
        <version>4.3.1</version>
    </dependency>
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>jquery</artifactId>
        <version>3.4.0</version>
    </dependency>
   <!-- rest of needed dependecies -->

org.webjars
独自创立
4.3.1
org.webjars
jquery
3.4.0
并将它们添加到模板标题中

<link rel="stylesheet" th:href="@{/webjars/bootstrap/4.3.1/css/bootstrap.min.css}"/>
<script th:href="@{/webjars/jquery/3.4.0/jquery.min.js} "></script>


然后,如果您运行Spring Boot应用程序并查看页面源代码,您可以通过在运行时单击该链接来访问此文件。

我也有此问题,似乎没有任何东西适合我。
... Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
   <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>bootstrap</artifactId>
        <version>4.3.1</version>
    </dependency>
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>jquery</artifactId>
        <version>3.4.0</version>
    </dependency>
   <!-- rest of needed dependecies -->
<link rel="stylesheet" th:href="@{/webjars/bootstrap/4.3.1/css/bootstrap.min.css}"/>
<script th:href="@{/webjars/jquery/3.4.0/jquery.min.js} "></script>