有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Web服务器无法启动。端口已在使用中。错误。但应用程序仍在运行

我正在制作一个spring启动应用程序。直到两天前,一切都很顺利。 当我启动我的应用程序时,我得到:

“应用程序无法启动。 Web服务器无法启动。端口8443已在使用中。"

但是。。。。当我检查我的邮递员时,应用程序正在运行。。。。所以错误不应该存在。我真的很想在这里得到一些帮助。我不知道我做错了什么。 我已经尝试了不同的端口,但这不是问题所在

这是我的“application.properties”

server.ssl.key-store=classpath:certificate.jks
server.ssl.key-store-type=pkcs12
server.ssl.key-store-password=password
server.ssl.key-password=password
server.ssl.key-alias=certificate
server.port=8443

spring.jpa.show-sql=true

spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.platform=postgres
spring.datasource.url=jdbc:postgresql://localhost:5432/java_backend_eind3
spring.datasource.username=username
spring.datasource.password=password
spring.jpa.database=POSTGRESQL
spring.jpa.generate-ddl=true
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
spring.jpa.properties.hibernate.dialect= org.hibernate.dialect.PostgreSQLDialect

spring.jpa.hibernate.ddl-auto= create
spring.datasource.initialization-mode=always

logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type=TRACE

还有我的pom。xml

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.4</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>nl.eind.java</groupId>
    <artifactId>backend</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>backend</name>
    <description>Java eindopdracht </description>
    <properties>
        <java.version>11</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-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</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>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-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>

共 (2) 个答案

  1. # 1 楼答案

    为了抓住java。网BindE异常,消息为:地址已在使用中

    try {
            SpringApplication.run(Application.class, args);
        } catch (org.springframework.boot.web.server.PortInUseException e) {
    //Runtime.exec("pkil")..
    //or
    SpringApplication.run(Application.class, otherargs);
    //SpringApplication.run(Application.class, new String[]{" server.port=8444"});
    //when invoked recursively it is a port rebalancer for port usage among port pool with server as from client for startup stage via application restarts within many busy ports which are used before or without querying.
    }
    
  2. # 2 楼答案

    如果您在windows上运行,您可以找到在端口上运行的进程,并使用下面的命令终止该进程,以便释放该端口

    netstat -ano | findstr :8443
    taskkill /pid "EnterProcessIdHere" /F
    
    

    对于linux

    lsof -i :8443
    kill EnterProcessIdHere