无法在Spring Boot应用程序(Tomcat服务器)中运行localhost [英] Unable to run localhost in Spring Boot application (Tomcat server)
问题描述
我一直在使用以下教程学习Spring: https://www. youtube.com/playlist?list=PLqq-6Pq4lTTbx8p2oCgcAQGQyqN8XeA1x
I've been learning Spring using the following tutorials: https://www.youtube.com/playlist?list=PLqq-6Pq4lTTbx8p2oCgcAQGQyqN8XeA1x
我创建了一个Maven项目,并尝试在参考这些视频的同时运行Spring Boot应用程序:
I have created a Maven project and tried to run the Spring Boot application while referring to these videos:
https://www.youtube .com/watch?v = E7_a-kB46LU& index = 9& list = PLqq-6Pq4lTTbx8p2oCgcAQGQyqN8XeA1x
我试图在Tomcat服务器上运行我的Spring应用程序,但是localhost无法正常工作. (端口8080)
I tried to run my Spring application on Tomcat server but the localhost isn't working. (Port 8080)
我的pom.xml看起来像这样:
My pom.xml looks like this:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.javabrains.springbootquickstart</groupId>
<artifactId>course-api-new</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Java Brains Course API</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
</project>
CourseApiApp.java:
CourseApiApp.java :
package io.javabrains.springbootstarter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class CourseApiApp {
public static void main(String[] args) {
SpringApplication.run(CourseApiApp.class, args);
}
}
根据视频本地主机,在运行应用程序时应显示白名单"错误,但根本不会运行.
According to the video localhost should display Whitelist error on running the application, but it doesn't run at all.
任何帮助将不胜感激,谢谢!
Any help would be appreciated, thanks!
推荐答案
我建议您从头开始项目.要创建有效的spring-boot
项目,您需要一个非常好的基于Web的生成器,用于spring-boot
入门应用程序.
I would suggest that you start your project from beginning. To create a valid spring-boot
project you have a very good web based generator for spring-boot
starter applications.
对于具有嵌入式tomcat的Web应用程序,应使用web
项目.
For a web application with an embedded tomcat you should use web
project.
使用STS
,您可以通过选择new -> spring starter project
来创建相同的内容.
Using STS
you can create the same by choosing new -> spring starter project
.
将出现一个向导,您可以选择项目信息:
A wizard will appear and you can choose your project informations:
然后在第二步中进行依赖:
And then in the second step you dependencies:
生成项目后,您的pom.xml
应该如下所示:
After generating your project your pom.xml
should look like that:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.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>
</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-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
您的应用程序应正常启动,并且tomcat在localhost:8080
上侦听.
Your application should start normally and tomcat listens on localhost:8080
.
编辑 入门者只有一个新设计:
EDIT The starter just have a new design:
这篇关于无法在Spring Boot应用程序(Tomcat服务器)中运行localhost的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!