java Web服务器启动失败,端口已在使用中错误,但应用程序仍在运行

ztyzrc3y  于 2023-06-28  发布在  Java
关注(0)|答案(3)|浏览(196)

我正在做一个Sping Boot 应用程序。两天前一切都很好。当我开始我的应用程序时,我得到:
“应用程序启动失败。Web服务器启动失败。端口8443已在使用中。”
但是....当我检查我的 Postman 时,应用程序正在运行....所以错误不应该在那里。我真的很感激你能帮我。我不知道我做错了什么。我已经尝试了不同的端口,但这不是问题所在。
这是我的“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>
carvr3hs

carvr3hs1#

如果你是在windows上运行,你可以找到在端口上运行的进程,并使用下面的命令杀死该进程,这样端口将被释放

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

对于linux

lsof -i :8443
kill EnterProcessIdHere
deyfvvtc

deyfvvtc2#

捕获java.net.BindException e,消息如下:地址已在使用中

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.
}
abithluo

abithluo3#

转到eclipse的控制台窗口,单击红色的停止按钮停止Tomcat和/或单击“删除所有终止的启动”,然后重新运行spring Boot 应用程序。
它清除/清除绑定到端口的先前应用示例。

相关问题