我正在开发这个spring-boot应用程序。该应用程序使用eclipse部署在tomcat服务器上,我只能访问index.html的内容,当我尝试从 index.html 导航到 folder_A的index.html 时,它将抛出whitelabel错误页面。
在浏览器控制台中,当导航到folder_A的index.html时,出现错误消息,指出未找到 folder_A 。
我项目的当前结构是:
Project +-- src | +--main | | +--java (Contains source code) | | +--resources | | | +--application.properties | | +--webapp | | | +--folder_A | | | | +--index.html | | | +--WEB_INF | | | | +--web.xml | | | +--index.html ````
web.xml 包含上一个项目的所有servlet映射, application.properties 当前为空。
为什么会这样?我需要配置哪些设置?
修改
在pom.xml中添加
<groupId>com.sampleproject</groupId>
<artifactId>TestProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>SpringProject</name>
<description>SpringProject</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.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>
<tomcat.version>7.0.75</tomcat.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-juli</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</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>
2017-03-02 08:57:55.467 INFO 8400 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2016 ms
2017-03-02 08:57:55.701 INFO 8400 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2017-03-02 08:57:55.713 INFO 8400 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-03-02 08:57:55.713 INFO 8400 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-03-02 08:57:55.713 INFO 8400 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-03-02 08:57:55.713 INFO 8400 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2017-03-02 08:57:56.135 INFO 8400 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@3901d134: startup date [Thu Mar 02 08:57:53 SGT 2017]; root of context hierarchy
2017-03-02 08:57:56.228 INFO 8400 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2017-03-02 08:57:56.228 INFO 8400 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2017-03-02 08:57:56.275 INFO 8400 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-03-02 08:57:56.275 INFO 8400 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-03-02 08:57:56.353 INFO 8400 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-03-02 08:57:56.385 INFO 8400 --- [ main] oConfiguration$WelcomePageHandlerMapping : Adding welcome page: ServletContext resource [/index.html]
2017-03-02 08:57:56.572 INFO 8400 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-03-02 08:57:56.697 INFO 8400 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2017-03-02 08:57:56.853 INFO 8400 --- [ main] c.s.SpringProjectApplication : Started SpringProjectApplication in 3.883 seconds (JVM running for 4.904)
2017-03-02 08:57:59.355 INFO 8400 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/ProjectName] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2017-03-02 08:57:59.355 INFO 8400 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2017-03-02 08:57:59.368 INFO 8400 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 13 ms
答案 0 :(得分:0)
如果您使用的是SpringBoot,那么您不需要web.xml,并将静态文件放在src / main / resources / static而不是src / main / webapp。
使用mvn spring-boot:run
命令启动它,不需要部署到Tomcat。
这是sample。