Spring 找不到该网址的网页:http://localhost:8080 春靴

Spring 找不到该网址的网页:http://localhost:8080 春靴,spring,spring-boot,Spring,Spring Boot,我已经启动了我的Spring boot应用程序,当我看到控制台时,应用程序已启动,但当我尝试打开浏览器运行时,它显示找不到网址的网页:。这里有什么问题?这是我的密码 import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class DemoApplic

我已经启动了我的Spring boot应用程序,当我看到控制台时,应用程序已启动,但当我尝试打开浏览器运行时,它显示找不到网址的网页:。这里有什么问题?这是我的密码

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);
    }

}
My login.html可在下找到

src/main/resources/templates/login.html 
这是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>
2018-12-19 17:04:35.175信息709136---[nio-8080-exec-1]o.s.web.servlet.DispatcherServlet:初始化servlet'DispatcherServlet' 2018-12-19 17:04:35.198信息709136---[nio-8080-exec-1]o.s.web.servlet.DispatcherServlet:在23毫秒内完成初始化


这里可能有什么问题?如果您有任何想法,我们将不胜感激。

如果您正在学习spring,您应该阅读有关控制器的内容。尝试创建一个示例控制器,然后在运行它时转到localhost:8080/您应该可以看到主页

@Controller
public class HomeController
{
    @GetMapping("/")
    public String homeInit() {
        return "home";
    }
}

如果您正在学习spring,您应该阅读有关控制器的内容。尝试创建一个示例控制器,然后在运行它时转到localhost:8080/您应该可以看到主页

@Controller
public class HomeController
{
    @GetMapping("/")
    public String homeInit() {
        return "home";
    }
}

使用提供的代码,针对应用程序启动GET将返回404spring引导页面,因为您不处理相对路径“/”


您必须添加一个控制器类(带有@Controller注释),指示请求映射和请求方法,并使用提供的代码呈现您想要的任何页面,针对应用程序启动GET将返回404 Spring引导页面,因为您不处理相对路径“/”


如果静态内容位于除
/static
/public
/resources
/META-INF/resources
以外的目录中,则必须添加一个控制器类(带有@Controller注释),指示请求映射和请求方法,并呈现所需的任何页面

然后将property
spring.resources.static locations
添加到
应用程序中。properties
指向静态内容

spring.resources.static-locations=classpath:/templates/
您将在控制台日志中看到以下消息:

Adding welcome page: class path resource [templates/index.html]
参考文献

默认情况下,SpringBoot从一个名为 /中的静态(或/public或/resources或/META-INF/resources) 类路径

还可以使用自定义静态资源位置 spring.resources.static-locations属性(替换默认值 包含目录位置列表的值)


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

然后将property
spring.resources.static locations
添加到
应用程序中。properties
指向静态内容

spring.resources.static-locations=classpath:/templates/
您将在控制台日志中看到以下消息:

Adding welcome page: class path resource [templates/index.html]
参考文献

默认情况下,SpringBoot从一个名为 /中的静态(或/public或/resources或/META-INF/resources) 类路径

还可以使用自定义静态资源位置 spring.resources.static-locations属性(替换默认值 包含目录位置列表的值)


你的日志没有说明任何错误。请发布您的控制器或将您的应用程序上载到github@georgesvan,它是关于指向login.html作为起始页,而不是关于controller@georgesvan,很抱歉,我无法将应用上载到github:(检查您的上下文路径,日志状态如下:
Tomcat已在端口上启动:8080(http),上下文路径为“”
。尝试将您的静态页面放在此处提到的某个位置:,它将能够直接访问。您的日志没有显示任何错误。请将您的控制器或应用上载到github@georgesvan,它是关于指向login.html作为起始页,而不是关于controller@georgesvan,很抱歉,我无法将应用程序上载到github:(检查您的上下文路径,日志声明如下:
Tomcat已在端口8080(http)上启动,上下文路径为“”
。尝试将静态页面放在此处提到的位置之一:,它将能够直接访问。但是,如果我想打开login.html,为什么要创建一个控制器?如果我想打开login.html,为什么要创建一个静态页面?但是,如果我想打开login.html,为什么要创建一个控制器?