Localhost拒绝使用Eclipse连接Spring Boot应用程序

时间:2019-04-05 18:24:54

标签: spring spring-boot localhost

 pom.xml file:


<?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>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>


    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.4.RELEASE</version>
    </parent>





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






    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId> 
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>
        <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>

java文件1:

package springWaterProj;


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


}

java文件2:

package springWaterProj;



import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class HelloController {


    @RequestMapping("/hello")
    public String sayHi() {
        return "hi"; 
    }
}

2 个答案:

答案 0 :(得分:0)

您的问题不完整。如果出现以下错误,则表明端口8080已被使用。

The Tomcat connector configured to listen on port 8080 failed to start. The port may already be in use or the connector may be misconfigured.

Action:

Verify the connector's configuration, identify and stop any process that's listening on port 8080, or configure this application to listen on another port.

在这种情况下,您可以停止在此端口上运行的应用程序,也可以仅使用其他端口。在您的application.properties文件中,您可以将端口定义为

server.port=8181

答案 1 :(得分:0)

  

解决方案1:终止流程

A simple solution is to terminate the process (in IDE) and clean and rebuild project.

点击红色按钮终止进程

Click on RED button to terminate process


  

解决方案2:更改端口

Change the port 
server.port=8088 # Server HTTP port.

  

解决方案3:使用cmd杀死进程

netstat -ano | findstr :<yourPortNumber>
taskkill /PID <typeyourPIDhere> /F