Java Spring boot war找不到index.html
我是Spring boot和tomcat的初学者,我发现了这个问题: 在tomcat服务器上部署spring引导war文件时,当我想将static index.html添加到war文件中时,会遇到一个问题 为了使其能够作为war部署,我将以下内容添加到我的应用程序类中:Java Spring boot war找不到index.html,java,spring,maven,tomcat,spring-boot,Java,Spring,Maven,Tomcat,Spring Boot,我是Spring boot和tomcat的初学者,我发现了这个问题: 在tomcat服务器上部署spring引导war文件时,当我想将static index.html添加到war文件中时,会遇到一个问题 为了使其能够作为war部署,我将以下内容添加到我的应用程序类中: @SpringBootApplication @ComponentScan(basePackages = {"com.app"}) @EnableMongoRepositories(basePackages = {"com.ap
@SpringBootApplication
@ComponentScan(basePackages = {"com.app"})
@EnableMongoRepositories(basePackages = {"com.app"})
public class MyApp extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(MyApp.class);
}
public static void main(String[] args) {
SpringApplication.run(MyApp.class, args);
}
}
现在应用程序可以工作了,但是index.html(位于src/main/resources下)不会显示(im获取白标签错误页面显示“出现意外错误(type=methodnotallowed,status=405)”。
请求方法“GET”不受支持)
但如果我像这样创建它:
@SpringBootApplication
@ComponentScan(basePackages = {"com.app"})
@EnableMongoRepositories(basePackages = {"com.app"})
public class MyApp {
public static void main(String[] args) {
SpringApplication.run(MyApp.class, args);
}
}
它向我显示index.html(但应用程序无法处理来自浏览器的GET请求,该请求在我获取HTTP状态404之前工作-请求的资源不可用)
我如何配置它,使它们都能工作
这是我的pom.xml
<packaging>war</packaging>
<build>
<finalName>myapp</finalName>
</build>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.1.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>1.8.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>rest-assured</artifactId>
<version>2.7.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
战争
myapp
org.springframework.boot
spring启动程序父级
1.3.1.发布
org.springframework.boot
SpringBootStarterWeb
org.springframework
弹簧芯
org.springframework.boot
spring启动程序数据mongodb
org.springframework.data
spring数据mongodb
1.8.1.1发布
org.springframework.boot
弹簧启动机tomcat
假如
朱尼特
朱尼特
4.12
测试
com.jayway.restassed
放心
2.7.0
测试
org.springframework
弹簧试验
测试
位于src/main/resources下
将index.html
添加到src/main/resources/public
目录中
根据:
默认情况下,SpringBoot将提供目录中的静态内容
在中调用/static(或/public或/resources或/META-INF/resources)
来自ServletContext根的类路径或
它不起作用。我尝试将index.hml放在以下路径中:/src/main/resources/public/index.html/src/main/resources/static/index.html/src/main/resources/index.html src/main/resources/META-INF/index.html,但没有成功,还是同一个白标签错误页面。(MyApp类位于src/main/java/com/app/main下)您是否向所有类添加了index.html?错误是什么?是的,我一次把它加到了所有的错误中。我得到的错误是:此应用程序没有/error的显式映射的白标签错误页,因此您将其视为一种回退。2016年1月12日星期二00:20:42发生意外错误(类型=方法不允许,状态=405)。请求方法“GET”不支持发送请求到哪个url
/
或index.html
?您是否在/
上定义了非GET
控制器方法?如果是,请将请求发送到/index.html