java - 尝试运行演示应用程序,但 tomcat 似乎正在运行,但浏览器正在抛出 404
问题描述
这是我的POM:
https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 org.springframework.boot spring-boot-starter-parent 2.2.0.M5 com.example demo 0.0.1-SNAPSHOT演示 Spring Boot 的演示项目
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-el</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-websocket</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>`enter code here`spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</pluginRepository>
</pluginRepositories>
这是我的主要课程:
@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(DemoApplication.class);
}
@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
return args -> {
System.out.println("Let's inspect the beans provided by Spring Boot:");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
};
}
}
这是我的控制器:
package com.example.demo;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@RestController
public class HelloController {
@RequestMapping("/hello")
public String index() {
return "Greetings from Spring Boot!";
}
}
输出表明一切都已启动并正在运行:
但是浏览器给了我 404 - 当我尝试做http://localhost:9080/hello时找不到
不知道发生了什么
Application.properties 文件:
server.port=9080
解决方案
推荐阅读
- javascript - 如何使用 ajax 将数据从 Javascript 传递到 PHP
- excel - Sumif 映射多个相同的行
- database - 减少PostgreSQL存储函数的执行时间
- python - Socketio 房间 - 如何获取所有房间的列表
- spring-boot - Spring Boot 和 Spring Data org.hibernate.exception.SQLGrammarException:无法提取 ResultSet
- datagrid - Microsoft Toolkit UWP DataGrid XAML 控件突出显示颜色
- javascript - 如何使用 nodeJS 从 JSON 对象中删除项目?
- python - 更优雅/pythonic的解压列表的方式?
- android - 如何在android中更新实时数据值
- security - SolrException:加载类“solr.RunExecutableListener”+“/var/tmp/sustes”进程时出错