我有一个带有几个控制器的简单弹簧启动应用程序。它还提供来自我的webapps目录的静态文件。因此,当我部署它时,我转到localhost:8080 /并从我的webapp / dir获取我的index.html。
当我在pom.xml中将包装更改为'jar',然后再次访问localhost:8080 /时,它不会获取index.html文件。 我希望更深入地了解为什么会发生这种情况,.war扩展会自动启用静态文件服务吗?如果是,那么弹簧靴配置?或者也许它是嵌入式tomcat处理jar和战争的不同?
<?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>lt.tomasirruta</groupId>
<artifactId>wedding</artifactId>
<version>0.0.1</version>
<packaging>war</packaging>
<name>wedding</name>
<description>WeddingApp</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<start.class>lt.tomasirruta.WeddingApplication</start.class>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>1.3.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.3-1100-jdbc41</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.3.3.RELEASE</version>
<configuration>
<mainClass>${start.class}</mainClass>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</build>
</project>
答案 0 :(得分:-1)
阅读以下链接。它解释了将静态文件放在Spring Boot中的位置: Static web content
尝试将index.html放在resources / public
下