即使在端口更改后,嵌入式tomcat也无法在Spring启动时启动

时间:2018-01-23 06:10:11

标签: spring spring-boot

嵌入式Tomcat未在spring boot应用程序中启动。我已经尝试阅读与更改端口号相关的所有解决方案。我尝试了所有那些仍然给我同样的错误。我甚至尝试过将端口号设为0仍然没有帮助。我已经添加了liquibase依赖,因为我创建了一个虚拟日志文件。但我想这不会导致问题。我尝试过其他Spring引导项目,但仍面临同样的问题。

  <?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.springboot.ashish</groupId>
        <artifactId>springbootdemo</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>jar</packaging>

        <name>springbootdemo</name>
        <description>Demo project for Spring Boot</description>

        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.5.9.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>
            <spring-cloud.version>Edgware.SR1</spring-cloud.version>
        </properties>

        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-actuator</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-actuator-docs</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-aop</artifactId>
            </dependency>
            <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.liquibase</groupId>
                <artifactId>liquibase-core</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-mail</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-social-facebook</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>

            <dependency>
                <groupId>com.h2database</groupId>
                <artifactId>h2</artifactId>
            </dependency>
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <scope>runtime</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>

            <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
    </dependency>

        </dependencies>
    <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>


    </project>

堆栈追踪:

2018-01-23 11:34:29.820  INFO 10432 --- [           main] o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 0
2018-01-23 11:34:29.961 DEBUG 10432 --- [           main] o.s.w.s.resource.ResourceUrlProvider     : Looking for resource handler mappings
2018-01-23 11:34:29.961 DEBUG 10432 --- [           main] o.s.w.s.resource.ResourceUrlProvider     : Found resource handler mapping: URL pattern="/**/favicon.ico", locations=[ServletContext resource [/], class path resource [META-INF/resources/], class path resource [resources/], class path resource [static/], class path resource [public/], class path resource []], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@37e64e37]
2018-01-23 11:34:29.961 DEBUG 10432 --- [           main] o.s.w.s.resource.ResourceUrlProvider     : Found resource handler mapping: URL pattern="/webjars/**", locations=[class path resource [META-INF/resources/webjars/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@31204303]
2018-01-23 11:34:29.961 DEBUG 10432 --- [           main] o.s.w.s.resource.ResourceUrlProvider     : Found resource handler mapping: URL pattern="/**", locations=[ServletContext resource [/], class path resource [META-INF/resources/], class path resource [resources/], class path resource [static/], class path resource [public/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@369fb99a]
2018-01-23 11:34:29.961 DEBUG 10432 --- [           main] o.s.w.s.resource.ResourceUrlProvider     : Found resource handler mapping: URL pattern="/docs/**", locations=[class path resource [META-INF/resources/spring-boot-actuator/docs/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@81a8898]
2018-01-23 11:34:51.050 ERROR 10432 --- [           main] o.a.coyote.http11.Http11NioProtocol      : Failed to start end point associated with ProtocolHandler ["http-nio-8056"]

java.io.IOException: Unable to establish loopback connection
    at sun.nio.ch.PipeImpl$Initializer.run(Unknown Source) ~[na:1.8.0_121]
    at sun.nio.ch.PipeImpl$Initializer.run(Unknown Source) ~[na:1.8.0_121]
    at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_121]
    at sun.nio.ch.PipeImpl.<init>(Unknown Source) ~[na:1.8.0_121]
    at sun.nio.ch.SelectorProviderImpl.openPipe(Unknown Source) ~[na:1.8.0_121]
    at java.nio.channels.Pipe.open(Unknown Source) ~[na:1.8.0_121]
    at sun.nio.ch.WindowsSelectorImpl.<init>(Unknown Source) ~[na:1.8.0_121]
    at sun.nio.ch.WindowsSelectorProvider.openSelector(Unknown Source) ~[na:1.8.0_121]
    at java.nio.channels.Selector.open(Unknown Source) ~[na:1.8.0_121]
    at org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector(NioSelectorPool.java:66) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
    at org.apache.tomcat.util.net.NioSelectorPool.open(NioSelectorPool.java:130) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
    at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:227) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
    at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:990) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
    at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:635) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
    at org.apache.catalina.connector.Connector.startInternal(Connector.java:1022) [tomcat-embed-core-8.5.23.jar:8.5.23]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [tomcat-embed-core-8.5.23.jar:8.5.23]
    at org.apache.catalina.core.StandardService.addConnector(StandardService.java:225) [tomcat-embed-core-8.5.23.jar:8.5.23]
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.addPreviouslyRemovedConnectors(TomcatEmbeddedServletContainer.java:250) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.start(TomcatEmbeddedServletContainer.java:193) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.startEmbeddedServletContainer(EmbeddedWebApplicationContext.java:297) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:145) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546) [spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
    at com.springboot.ashish.springbootdemo.SpringbootdemoApplication.main(SpringbootdemoApplication.java:23) [classes/:na]
Caused by: java.net.ConnectException: Connection timed out: connect
    at sun.nio.ch.Net.connect0(Native Method) ~[na:1.8.0_121]
    at sun.nio.ch.Net.connect(Unknown Source) ~[na:1.8.0_121]
    at sun.nio.ch.Net.connect(Unknown Source) ~[na:1.8.0_121]
    at sun.nio.ch.SocketChannelImpl.connect(Unknown Source) ~[na:1.8.0_121]
    at java.nio.channels.SocketChannel.open(Unknown Source) ~[na:1.8.0_121]
    at sun.nio.ch.PipeImpl$Initializer$LoopbackConnector.run(Unknown Source) ~[na:1.8.0_121]
    ... 29 common frames omitted

2018-01-23 11:34:51.052 ERROR 10432 --- [           main] o.apache.catalina.core.StandardService   : Failed to start connector [Connector[HTTP/1.1-8056]]

org.apache.catalina.LifecycleException: Failed to start component [Connector[HTTP/1.1-8056]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
    at org.apache.catalina.core.StandardService.addConnector(StandardService.java:225) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.addPreviouslyRemovedConnectors(TomcatEmbeddedServletContainer.java:250) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.start(TomcatEmbeddedServletContainer.java:193) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.startEmbeddedServletContainer(EmbeddedWebApplicationContext.java:297) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:145) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546) [spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
    at com.springboot.ashish.springbootdemo.SpringbootdemoApplication.main(SpringbootdemoApplication.java:23) [classes/:na]
Caused by: org.apache.catalina.LifecycleException: service.getName(): "Tomcat";  Protocol handler start failed
    at org.apache.catalina.connector.Connector.startInternal(Connector.java:1031) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
    ... 13 common frames omitted
Caused by: java.io.IOException: Unable to establish loopback connection
    at sun.nio.ch.PipeImpl$Initializer.run(Unknown Source) ~[na:1.8.0_121]
    at sun.nio.ch.PipeImpl$Initializer.run(Unknown Source) ~[na:1.8.0_121]
    at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_121]
    at sun.nio.ch.PipeImpl.<init>(Unknown Source) ~[na:1.8.0_121]
    at sun.nio.ch.SelectorProviderImpl.openPipe(Unknown Source) ~[na:1.8.0_121]
    at java.nio.channels.Pipe.open(Unknown Source) ~[na:1.8.0_121]
    at sun.nio.ch.WindowsSelectorImpl.<init>(Unknown Source) ~[na:1.8.0_121]
    at sun.nio.ch.WindowsSelectorProvider.openSelector(Unknown Source) ~[na:1.8.0_121]
    at java.nio.channels.Selector.open(Unknown Source) ~[na:1.8.0_121]
    at org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector(NioSelectorPool.java:66) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
    at org.apache.tomcat.util.net.NioSelectorPool.open(NioSelectorPool.java:130) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
    at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:227) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
    at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:990) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
    at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:635) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
    at org.apache.catalina.connector.Connector.startInternal(Connector.java:1022) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
    ... 14 common frames omitted
Caused by: java.net.ConnectException: Connection timed out: connect
    at sun.nio.ch.Net.connect0(Native Method) ~[na:1.8.0_121]
    at sun.nio.ch.Net.connect(Unknown Source) ~[na:1.8.0_121]
    at sun.nio.ch.Net.connect(Unknown Source) ~[na:1.8.0_121]
    at sun.nio.ch.SocketChannelImpl.connect(Unknown Source) ~[na:1.8.0_121]
    at java.nio.channels.SocketChannel.open(Unknown Source) ~[na:1.8.0_121]
    at sun.nio.ch.PipeImpl$Initializer$LoopbackConnector.run(Unknown Source) ~[na:1.8.0_121]
    ... 29 common frames omitted

2018-01-23 11:34:51.069  INFO 10432 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2018-01-23 11:34:51.084  INFO 10432 --- [           main] utoConfigurationReportLoggingInitializer : 

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-01-23 11:34:51.100 ERROR 10432 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

The Tomcat connector configured to listen on port 8056 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 8056, or configure this application to listen on another port.

1 个答案:

答案 0 :(得分:1)

尝试杀死你的tomcat / java运行实例

  • 在Windows中 - &gt;打开任务管理器转到所有java实例的进程列表 在内存中运行
  • 在Linux系统中使用:ps -aef | grep java它会显示列表 运行tomcat和java的实例关闭all而不是再试一次。

希望它能解决您的问题,您也可以检查您的application.properties文件,如下所示

#--------------------------------
# Tomcat Port 
#----------------------------------
server.port = 8080

# ----------------------------------------
# Logging Level
# ----------------------------------------
logging.level.root=error
logging.level.org.springframework=info
logging.level.org.hibernate=error

# ----------------------------------------
# MySQL DataBase Connection Properties
# ----------------------------------------
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://localhost:3306/db
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.show-sql=true

# ----------------------------------------
# ACTUATOR PROPERTIES
# ----------------------------------------
endpoints.actuator.enabled=false
management.security.enabled=false

# ----------------------------------------
# DevTols PROPERTIES
# ----------------------------------------
spring.devtools.restart.enabled=true

# ----------------------------------------
# JSP PREFIX/POSTFIX PROPERTIES
# ----------------------------------------
#spring.thymeleaf.prefix=/view/
#spring.thymeleaf.suffix=.html