Spring boot中没有找到该网址的网页:http://localhost:8080 [英] No webpage was found for the web address: http://localhost:8080 in Spring boot

查看:48
本文介绍了Spring boot中没有找到该网址的网页:http://localhost:8080的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经启动了我的 Spring boot 应用程序,当我看到控制台时应用程序已经启动,但是当我尝试打开浏览器运行时,它显示没有找到该网址的网页:http://localhost:8080/Demo/login.html.这里有什么问题?这是我的代码

I've started my Spring boot application, and the applicaiton has started when I see the console, but when I try to open the browser to run, it shows No webpage was found for the web address: http://localhost:8080/Demo/login.html. What is the problem here? Here is my code

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication .class, args);
    }

}

我的 login.html 在

My login.html is available under

src/main/resources/templates/login.html 

这里是 pom.xml

Here is the pom.xml

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <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>
    <resources>
         <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

日志显示很清楚,Tomcat服务器在8080端口号启动

Log it shows clearly as Tomcat server started at 8080 port number

 2018-12-19 17:02:24.213  INFO 709136 --- [           main] 
com.test.demo.DemoApplication          : Starting DemoApplication on Test with PID 709136 (C:\Users\Syed\Documents\DEMO\DEMO\target\classes started by Syed in C:\Users\Syed\Documents\DEMO\DEMO)
 2018-12-19 17:02:24.254  INFO 709136 --- [           main] 
 com.test.demo.DemoApplication          : The following profiles are active: @spring.profiles.active@
2018-12-19 17:02:25.674  INFO 709136 --- [           main] 
o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2018-12-19 17:02:25.705  INFO 709136 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-12-19 17:02:25.706  INFO 709136 --- [           main] 
org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/9.0.13
2018-12-19 17:02:25.715  INFO 709136 --- [           main] 
o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jdk1.8.0_45\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jdk1.8.0_45/bin/../jre/bin/server;C:/Program Files/Java/jdk1.8.0_45/bin/../jre/bin;C:/Program Files/Java/jdk1.8.0_45/bin/../jre/lib/amd64;C:\Program Files (x86)\RSA SecurID Token Common;C:\Program Files\RSA SecurID Token Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Citrix\System32\;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\McAfee\Solidcore\Tools\GatherInfo;C:\Program Files\McAfee\Solidcore\Tools\Scanalyzer;C:\Program Files\McAfee\Solidcore\;C:\Program Files\McAfee\Solidcore\Tools\ScGetCerts;C:\Program Files\Citrix\System32\;C:\Program Files\Citrix\ICAService\;C:\Program Files\Common Files\Hitachi ID\;C:\Program Files\nodejs\;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Java\jdk1.8.0_45\bin;C:\Program Files\Java\jdk1.8.0_45\jre\bin;C:\Users\AF68935\AppData\Roaming\npm;C:\Users\AF68935\AppData\Roaming\npm\node_modules\@angular\cli\bin;;C:\Users\AF68935\Downloads\spring-tool-suite-4-4.0.2.RELEASE-e4.9.0-win32.win32.x86_64\sts-4.0.2.RELEASE;;.]
2018-12-19 17:02:25.837  INFO 709136 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
 2018-12-19 17:02:25.837  INFO 709136 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1510 ms
2018-12-19 17:02:26.214  INFO 709136 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2018-12-19 17:02:26.523  INFO 709136 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2018-12-19 17:02:26.542  INFO 709136 --- [           main] com.test.demo.DemoApplication          : Started DemoApplication in 2.95 seconds (JVM running for 3.852)
2018-12-19 17:04:35.175  INFO 709136 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'

2018-12-19 17:04:35.175 INFO 709136 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet:初始化 Servlet 'dispatcherServlet'2018-12-19 17:04:35.198 INFO 709136 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet:在 23 毫秒内完成初始化

2018-12-19 17:04:35.175 INFO 709136 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet' 2018-12-19 17:04:35.198 INFO 709136 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 23 ms

这里可能有什么问题?任何想法将不胜感激.

What could be the issue here? Any ideas would be greatly appreciated.

推荐答案

如果您的静态内容位于 /static/public 以外的目录中>/resources/META-INF/resources.

If your static content is located in a directory other than /static, /public, /resources or /META-INF/resources.

然后将属性 spring.resources.static-locations 添加到您的 application.properties 以指向静态内容.

Then add property spring.resources.static-locations to your application.properties to point to the static content.

spring.resources.static-locations=classpath:/templates/

您将在控制台日志中看到以下消息:

You will see the following message in the console log:

Adding welcome page: class path resource [templates/index.html]

参考文档

默认情况下,Spring Boot 从名为的目录提供静态内容/static(或/public 或/resources 或/META-INF/resources)在类路径

By default, Spring Boot serves static content from a directory called /static (or /public or /resources or /META-INF/resources) in the classpath

您还可以使用spring.resources.static-locations 属性(替换默认值带有目录位置列表的值).

You can also customize the static resource locations by using the spring.resources.static-locations property (replacing the default values with a list of directory locations).

这篇关于Spring boot中没有找到该网址的网页:http://localhost:8080的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆