我使用了bower.json文件中的依赖项
{
"name": "bower",
"description": "This is a Spring Boot Application",
"main": "index.html",
"authors": [
"Mark Lee S. Castillo <castillolee@yahoo.com>"
],
"license": "MIT",
"homepage": "",
"private": true,
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"angular": "1.4.7",
"angular-animate": "~1.4.7",
"angular-ui-router": "0.2.15",
"angular-bootstrap": "0.13.4",
"angular-local-storage": "0.2.2",
"angular-moment": "0.10.3",
"angular-filter": "0.5.17",
"angular-sanitize": "1.4.7",
"font-awesome": "4.4.0",
"jquery": "2.1.4",
"selectize": "0.12.1",
"ui-select": "angular-ui-select#0.13.2",
"ng-file-upload": "6.0.4",
"chart.js": "2.5.0",
"jspdf": "jsPDF-html2canvas#^1.2.61",
"html2canvas": "0.4.1",
"bootstrap": "3.3.7",
"angular-bootstrap-datetimepicker-directive": "0.1.3"
}
}
到我的index.html文件
<!DOCTYPE html>
<html>
<head>
<title>Spring Boot Application</title>
<link rel="stylesheet" type="text/css"
<href
="/bower_components/bootstrap/dist/css/bootstrap.min.css">
</head>
<body>
<h1>Spring Boot Application</h1>
</body>
</html>
当我在标题下添加href
行时,我得到一个whitelabel错误页面,但当我删除它时,它工作正常。这是我创建的一个新项目。
这是我的index.html
的控制器import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class springbootapplicationController {
@RequestMapping("/")
public String welcomeController(ModelMap model) {
model.put("welcome", "Spring boot application");
return "index";
}
}
我正在使用Spring启动,这是我的依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.spring</groupId>
<artifactId>springbootapplication</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>springbootapplication</name>
<description>Spring Project</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
我无法找到导致错误的原因。
答案 0 :(得分:0)
这是百里香通告诉你,那里有一些无效的XHTML。 Thymeleaf是 XML ,因此您必须关闭所有元素。 此外,您有一个无效的前导'&lt;'在href属性之前。
<!DOCTYPE html>
<html>
<head>
<title>Spring Boot Application</title>
<link
rel="stylesheet"
type="text/css"
href="/bower_components/bootstrap/dist/css/bootstrap.min.css"/>
</head>
<body>
<h1>Spring Boot Application</h1>
</body>
</html>
我应该补充一点,因为这是你正在使用的Thymeleaf,你应该添加模式参考。 模板将如下所示:
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Spring Boot Application</title>
<link
rel="stylesheet"
type="text/css"
th:href="@{/bower_components/bootstrap/dist/css/bootstrap.min.css}"/>
</head>
<body>
<h1>Spring Boot Application</h1>
</body>
</html>