【问题标题】:Launching Spring application Address already in use正在启动 Spring 应用程序地址已在使用中
【发布时间】:2014-01-11 04:19:13
【问题描述】:

我在启动我的 spring 应用程序时遇到此错误:

java -jar target/gs-serving-web-content-0.1.0.jar

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::             (v0.5.0.M6)

2013-12-23 00:23:09.466  INFO 19252 --- [           main] hello.Application                        : Starting Application on mbp-de-antoine.home with PID 19252 (/Users/antoine/Documents/workspace-sts-3.4.0.RELEASE/springapp/target/gs-serving-web-content-0.1.0.jar started by antoine)
2013-12-23 00:23:09.511  INFO 19252 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@24024c39: startup date [Mon Dec 23 00:23:09 CET 2013]; root of context hierarchy
2013-12-23 00:23:10.910  INFO 19252 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2013-12-23 00:23:10.910  INFO 19252 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/7.0.42
2013-12-23 00:23:11.045  INFO 19252 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2013-12-23 00:23:11.046  INFO 19252 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1537 ms
2013-12-23 00:23:11.274  INFO 19252 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
2013-12-23 00:23:11.274  INFO 19252 --- [ost-startStop-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
2013-12-23 00:23:11.409  INFO 19252 --- [ost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2013-12-23 00:23:11.634  INFO 19252 --- [ost-startStop-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/greeting],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String hello.GreetingController.greeting(java.lang.String,org.springframework.ui.Model)
2013-12-23 00:23:11.717  INFO 19252 --- [ost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2013-12-23 00:23:11.717  INFO 19252 --- [ost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2013-12-23 00:23:12.406  INFO 19252 --- [ost-startStop-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 1132 ms
2013-12-23 00:23:12.417 ERROR 19252 --- [           main] o.a.coyote.http11.Http11NioProtocol      : Failed to start end point associated with ProtocolHandler ["http-nio-8080"]

java.net.BindException: Address already in use
    at sun.nio.ch.Net.bind0(Native Method)
    at sun.nio.ch.Net.bind(Net.java:444)
    at sun.nio.ch.Net.bind(Net.java:436)
    at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:214)
    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
    at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:473)
    at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:617)
    at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:444)
    at org.apache.catalina.connector.Connector.startInternal(Connector.java:1010)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:459)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:732)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.startup.Tomcat.start(Tomcat.java:335)
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:58)
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.<init>(TomcatEmbeddedServletContainer.java:53)
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:259)
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:140)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:158)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:135)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:476)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:552)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:293)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:749)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:738)
    at hello.Application.main(Application.java:12)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
    at java.lang.Thread.run(Thread.java:744)

2013-12-23 00:23:12.419 ERROR 19252 --- [           main] o.apache.catalina.core.StandardService   : Failed to start connector [Connector[org.apache.coyote.http11.Http11NioProtocol-8080]]

org.apache.catalina.LifecycleException: Failed to start component [Connector[org.apache.coyote.http11.Http11NioProtocol-8080]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:459)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:732)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.startup.Tomcat.start(Tomcat.java:335)
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:58)
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.<init>(TomcatEmbeddedServletContainer.java:53)
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:259)
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:140)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:158)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:135)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:476)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:552)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:293)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:749)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:738)
    at hello.Application.main(Application.java:12)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
    at java.lang.Thread.run(Thread.java:744)
Caused by: org.apache.catalina.LifecycleException: service.getName(): "Tomcat";  Protocol handler start failed
    at org.apache.catalina.connector.Connector.startInternal(Connector.java:1017)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 24 common frames omitted
Caused by: java.net.BindException: Address already in use
    at sun.nio.ch.Net.bind0(Native Method)
    at sun.nio.ch.Net.bind(Net.java:444)
    at sun.nio.ch.Net.bind(Net.java:436)
    at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:214)
    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
    at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:473)
    at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:617)
    at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:444)
    at org.apache.catalina.connector.Connector.startInternal(Connector.java:1010)
    ... 25 common frames omitted

2013-12-23 00:23:12.420  INFO 19252 --- [           main] o.apache.catalina.core.StandardService   : Stopping service Tomcat
2013-12-23 00:23:12.430  INFO 19252 --- [           main] nitializer$AutoConfigurationReportLogger : 


=========================
AUTO-CONFIGURATION REPORT
=========================


Positive matches:
-----------------

   MessageSourceAutoConfiguration
      - @ConditionalOnMissingBean (types: org.springframework.context.MessageSource; SearchStrategy: all) found no beans (OnBeanCondition)

   PropertyPlaceholderAutoConfiguration#propertySourcesPlaceholderConfigurer
      - @ConditionalOnMissingBean (types: org.springframework.context.support.PropertySourcesPlaceholderConfigurer; SearchStrategy: current) found no beans (OnBeanCondition)

   ThymeleafAutoConfiguration
      - @ConditionalOnClass classes found: org.thymeleaf.spring3.SpringTemplateEngine (OnClassCondition)
      - @ConditionalOnClass classes found: org.thymeleaf.spring3.SpringTemplateEngine (OnClassCondition)

   ThymeleafAutoConfiguration.DefaultTemplateResolverConfiguration
      - @ConditionalOnMissingBean (names: defaultTemplateResolver; SearchStrategy: all) found no beans (OnBeanCondition)

   ThymeleafAutoConfiguration.ThymeleafDefaultConfiguration
      - @ConditionalOnMissingBean (types: org.thymeleaf.spring3.SpringTemplateEngine; SearchStrategy: all) found no beans (OnBeanCondition)

   ThymeleafAutoConfiguration.ThymeleafViewResolverConfiguration
      - @ConditionalOnClass classes found: javax.servlet.Servlet (OnClassCondition)
      - @ConditionalOnClass classes found: javax.servlet.Servlet (OnClassCondition)

   ThymeleafAutoConfiguration.ThymeleafViewResolverConfiguration#thymeleafViewResolver
      - @ConditionalOnMissingBean (names: thymeleafViewResolver; SearchStrategy: all) found no beans (OnBeanCondition)

   DispatcherServletAutoConfiguration
      - found web application StandardServletEnvironment (OnWebApplicationCondition)
      - @ConditionalOnClass classes found: org.springframework.web.servlet.DispatcherServlet (OnClassCondition)
      - found web application StandardServletEnvironment (OnWebApplicationCondition)
      - @ConditionalOnClass classes found: org.springframework.web.servlet.DispatcherServlet (OnClassCondition)
      - @ConditionalOnBean (types: org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; SearchStrategy: all) found the following [tomcatEmbeddedServletContainerFactory] (OnBeanCondition)

   DispatcherServletAutoConfiguration#dispatcherServlet
      - no DispatcherServlet found (DispatcherServletAutoConfiguration.DefaultDispatcherServletCondition)

   EmbeddedServletContainerAutoConfiguration
      - found web application StandardServletEnvironment (OnWebApplicationCondition)
      - found web application StandardServletEnvironment (OnWebApplicationCondition)

   EmbeddedServletContainerAutoConfiguration.EmbeddedTomcat
      - @ConditionalOnClass classes found: javax.servlet.Servlet,org.apache.catalina.startup.Tomcat (OnClassCondition)
      - @ConditionalOnClass classes found: javax.servlet.Servlet,org.apache.catalina.startup.Tomcat (OnClassCondition)
      - @ConditionalOnMissingBean (types: org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; SearchStrategy: current) found no beans (OnBeanCondition)

   ServerPropertiesAutoConfiguration#serverProperties
      - @ConditionalOnMissingBean (types: org.springframework.boot.context.embedded.properties.ServerProperties; SearchStrategy: all) found no beans (OnBeanCondition)

   WebMvcAutoConfiguration
      - found web application StandardServletEnvironment (OnWebApplicationCondition)
      - @ConditionalOnClass classes found: javax.servlet.Servlet,org.springframework.web.servlet.DispatcherServlet,org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter (OnClassCondition)
      - found web application StandardServletEnvironment (OnWebApplicationCondition)
      - @ConditionalOnClass classes found: javax.servlet.Servlet,org.springframework.web.servlet.DispatcherServlet,org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter (OnClassCondition)
      - @ConditionalOnMissingBean (types: org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; SearchStrategy: all) found no beans (OnBeanCondition)

   WebMvcAutoConfiguration#hiddenHttpMethodFilter
      - @ConditionalOnMissingBean (types: org.springframework.web.filter.HiddenHttpMethodFilter; SearchStrategy: all) found no beans (OnBeanCondition)

   WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#defaultViewResolver
      - @ConditionalOnMissingBean (types: org.springframework.web.servlet.view.InternalResourceViewResolver; SearchStrategy: all) found no beans (OnBeanCondition)


Negative matches:
-----------------

   RabbitAutoConfiguration
      - required @ConditionalOnClass classes not found: org.springframework.amqp.rabbit.core.RabbitTemplate,com.rabbitmq.client.Channel (OnClassCondition)

   AopAutoConfiguration
      - required @ConditionalOnClass classes not found: org.aspectj.lang.annotation.Aspect,org.aspectj.lang.reflect.Advice (OnClassCondition)

   BatchAutoConfiguration
      - required @ConditionalOnClass classes not found: org.springframework.batch.core.launch.JobLauncher (OnClassCondition)

   JpaRepositoriesAutoConfiguration
      - required @ConditionalOnClass classes not found: org.springframework.data.jpa.repository.JpaRepository (OnClassCondition)

   MongoRepositoriesAutoConfiguration
      - required @ConditionalOnClass classes not found: com.mongodb.Mongo,org.springframework.data.mongodb.repository.MongoRepository (OnClassCondition)

   DataSourceAutoConfiguration
      - required @ConditionalOnClass classes not found: org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType (OnClassCondition)

   DataSourceTransactionManagerAutoConfiguration
      - required @ConditionalOnClass classes not found: org.springframework.jdbc.core.JdbcTemplate,org.springframework.transaction.PlatformTransactionManager (OnClassCondition)

   JmsTemplateAutoConfiguration
      - required @ConditionalOnClass classes not found: org.springframework.jms.core.JmsTemplate,javax.jms.ConnectionFactory (OnClassCondition)

   DeviceResolverAutoConfiguration
      - required @ConditionalOnClass classes not found: org.springframework.mobile.device.DeviceResolverHandlerInterceptor,org.springframework.mobile.device.DeviceHandlerMethodArgumentResolver (OnClassCondition)

   HibernateJpaAutoConfiguration
      - required @ConditionalOnClass classes not found: org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean,org.springframework.transaction.annotation.EnableTransactionManagement,javax.persistence.EntityManager,org.hibernate.ejb.HibernateEntityManager (OnClassCondition)

   ReactorAutoConfiguration
      - required @ConditionalOnClass classes not found: reactor.spring.context.config.EnableReactor (OnClassCondition)

   ThymeleafAutoConfiguration.ThymeleafSecurityDialectConfiguration
      - required @ConditionalOnClass classes not found: org.thymeleaf.extras.springsecurity3.dialect.SpringSecurityDialect (OnClassCondition)

   ThymeleafAutoConfiguration.ThymeleafWebLayoutConfiguration
      - required @ConditionalOnClass classes not found: nz.net.ultraq.thymeleaf.LayoutDialect (OnClassCondition)

   EmbeddedServletContainerAutoConfiguration.EmbeddedJetty
      - required @ConditionalOnClass classes not found: org.eclipse.jetty.server.Server,org.eclipse.jetty.util.Loader (OnClassCondition)

   MultipartAutoConfiguration
      - @ConditionalOnClass classes found: javax.servlet.Servlet,org.springframework.web.multipart.support.StandardServletMultipartResolver (OnClassCondition)
      - @ConditionalOnClass classes found: javax.servlet.Servlet,org.springframework.web.multipart.support.StandardServletMultipartResolver (OnClassCondition)
      - @ConditionalOnBean (types: javax.servlet.MultipartConfigElement; SearchStrategy: all) found no beans (OnBeanCondition)

   WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#beanNameViewResolver
      - @ConditionalOnBean (types: org.springframework.web.servlet.View; SearchStrategy: all) found no beans (OnBeanCondition)

   WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#viewResolver
      - @ConditionalOnBean (types: org.springframework.web.servlet.View; SearchStrategy: all) found no beans (OnBeanCondition)

   WebSocketAutoConfiguration
      - required @ConditionalOnClass classes not found: org.springframework.web.socket.WebSocketHandler (OnClassCondition)



java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
    at java.lang.Thread.run(Thread.java:744)
Caused by: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embdedded Tomcat
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:138)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:476)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:552)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:293)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:749)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:738)
    at hello.Application.main(Application.java:12)
    ... 6 more
Caused by: org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embdedded Tomcat
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:85)
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.<init>(TomcatEmbeddedServletContainer.java:53)
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:259)
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:140)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:158)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:135)
    ... 13 more
Caused by: java.lang.IllegalStateException: Tomcat connector in failed state
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:81)
    ... 18 more

我认为这是因为我的端口被使用了。我的 8080 端口被使用,所以我尝试使用 8181 端口 我在 8181 端口上没有应用程序

在 tomcat server.xml 中我将端口设置为 8181,但问题仍然存在

我找到了这篇文章:

Alternate port for Tomcat (not 8080) when starting with Maven?

但是我在启动 mvn -Dmaven.tomcat.port=8181 tomcat:run-war 后遇到了同样的问题

我不太明白maven是如何链接到tomcat服务器的 这是我的 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.springframework</groupId>
    <artifactId>gs-serving-web-content</artifactId>
    <version>0.1.0</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>0.5.0.M6</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf-spring3</artifactId>
        </dependency>
    </dependencies>

    <properties>
        <start-class>hello.Application</start-class>
    </properties>

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

    <repositories>
        <repository>
            <id>spring-milestone</id>
            <url>http://repo.spring.io/libs-milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-milestone</id>
            <url>http://repo.spring.io/libs-milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

</project>

感谢您的帮助

【问题讨论】:

  • 首先确保这些端口“真正”可用。现在我猜您正在使用一些 *Unix 系统(我从路径分隔符猜测),打开您的终端并运行 netstat -tuplen 以获取已使用端口及其各自进程 ID 的完整列表。在启动 tomcat 之前从那里验证端口是否空闲
  • 是的,我的 8181 端口是免费的
  • 检查默认端口(8080)是否正在运行。在 Windows 中使用 > netstat -a -o -n 然后搜索您的端口号是否正在运行......如果它正在运行,请记下对应的 pid。 taskkill /f /pid {pidno}
  • 配置文件中的错误IP也会导致此异常。

标签: java spring maven tomcat spring-mvc


【解决方案1】:

Spring Boot 默认使用嵌入式 Tomcat,但不使用tomcat-maven-plugin 的处理方式不同。要更改端口,请使用--server.port 参数,例如:

java -jar target/gs-serving-web-content-0.1.0.jar --server.port=8181

更新。或者将server.port=8181 放入application.properties(或application.yml)。

【讨论】:

  • 是否可以在配置中设置?比如使用注解?
  • server.port=8181 放入您的 application.properties 文件中也应该可以。
  • 别忘了清理和构建......这也有帮助
  • application.properties 文件的更好选择是包含一个具有覆盖能力的默认值 server.port=${port:8181}
  • 非常感谢!我整天都在搜索该解决方案,并在添加 --server.port=8181 后解决了。谢谢
【解决方案2】:

运行以下命令搜索正在使用该端口的进程

lsof -i :<portNumber> | grep LISTEN

在你的情况下,这将是 -->

lsof -i :8080 | grep LISTEN
java    78960 xyxss  119u  IPv6 0x6c20d372bc88c27d      0t0  TCP *:8092 (LISTEN)

78960是进程id,使用如下命令杀死进程

kill -9 78960

再次启动应用程序。

【讨论】:

  • 我必须使用这个命令让它在我的 mac 上工作:sudo lsof -n -P |听听。 Mac 会在您使用 sudo 时提示您输入密码。
  • 感谢您的回答。只有此解决方案适用于 IntelliJ
  • 我有 macOS Big Sur,这非常有效。谢谢。
【解决方案3】:

/src/main/resources/application.properties中配置另一个端口号(例如:8181)

server.port=8181

【讨论】:

  • @Junchen Lui 那是因为它只是一种解决方法。如果您一直这样做,您将运行大量未使用的 tomcat。最好首先修复错误。
  • dam,这真的可以不用配置任何 xml 或设置 projecto
【解决方案4】:

您需要在重新启动之前停止服务器。寻找红框图标或服务器视图。

【讨论】:

【解决方案5】:

在我的情况下,查看服务器窗口只显示了一个我从未用于此项目的 tomcat 服务器。我的 SpringBoot 项目使用了一个嵌入式 tomcat 服务器,当我的应用程序完成时它并没有停止。我用红色箭头指示的这个按钮将停止应用程序和 Tomcat 服务器,所以下次我运行应用程序时,我不会收到 Tomcat 实例已在端口 8080 上运行的错误。

实际错误信息:

验证连接器的配置,识别并停止任何进程 正在侦听端口 8080,或配置此应用程序以侦听 在另一个端口上。

引起:java.net.BindException:地址已在使用中引起: org.apache.catalina.LifecycleException: service.getName(): "Tomcat"; 协议处理程序启动失败

我现在将在本教程https://spring.io/guides/gs/consuming-rest/ 中寻找一种在完成我的 SpringBoot Consuming Rest 应用程序后关闭所有服务的方法@

弹簧启动

【讨论】:

    【解决方案6】:

    这个错误基本上发生在特定端口不空闲时。所以有两种解决方案,您可以通过终止或关闭正在使用它的服务来释放该端口,或者您可以在不同的端口上运行您的应用程序(tomcat)。

    解决方案 1:释放端口

    在 Linux 机器上,您可以找到端口使用者的进程 ID,然后将其杀死。使用如下命令(假设默认端口为8080)

    netstat -pnltu | grep -i "8080"
    

    上述命令的输出类似于:

    tcp6   0  0 :::8080    :::*      LISTEN      20674/java 
    

    然后你可以很容易地用它的 processid 杀死这个进程:

    kill 20674
    

    在 Windows 机器上查找进程 ID 使用 netstat -ano -p tcp |find "8080"。要杀死进程,请使用taskkill /F /PID 1234(而不是 1234 输入创建的进程 ID)。

    解决方案 2:更改默认端口

    在开发过程中开发人员使用port 8080,您可以轻松更改它。您需要使用以下规范在项目的 application.properties 文件 (/src/main/resources/application.properties) 中指定所需的端口号:

    server.port=8081
    

    您还可以在执行.jar 文件时设置备用端口号

    - java -jar spring-boot-application.jar --server.port=8081
    

    请注意,有时(不一定)您也必须更改其他端口,例如:

    management.port=
    tomcat.jvmroute=
    tomcat.ajp.port=
    tomcat.ajp.redirectPort=
    etc...
    

    【讨论】:

      【解决方案7】:

      使用 IntelliJ 时,当我尝试运行 Spring 应用程序时出现此错误,而此时已有一个应用程序正在运行。我不得不停止第一个。之后,运行第二个应用程序没有返回任何错误。

      【讨论】:

        【解决方案8】:

        首先,检查谁使用了 8080 端口。

        如果8080端口正在使用,则将监听端口改为8181。

        如果你使用IDEA,修改启动配置, 运行-> 编辑配置 enter image description here

        如果你使用mvn spring-boot,那么使用命令:

        mvn spring-boot:run -Dserver.port=8181
        

        如果你使用java -jar,那么使用命令:

        java -jar xxxx.jar --server.port=8181
        

        【讨论】:

          【解决方案9】:

          这仅对我有效,方法是设置其他属性并使用可用的任意端口号,如下所示:

          • YML

          /src/main/resources/application.yml

          server:
            port: 18181
          management:
            port: 9191
          tomcat:
            jvmroute: 5478
            ajp:
              port: 4512
              redirectPort: 1236
          
          • 属性

          /src/main/resources/application.properties

          server.port=18181
          management.port=9191
          tomcat.jvmroute=5478
          tomcat.ajp.port=4512
          tomcat.ajp.redirectPort=1236     
          

          【讨论】:

          • 这对我有用。在 Spring boot 2.0.3.RELEASE 中,management.port 键被替换为 management.server.port
          • tomcat.jvmroute=5478 帮助我运行了两个应用程序实例以及 server.port=18181
          【解决方案10】:

          我建议终止端口号。它对我有用

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

          【讨论】:

            【解决方案11】:

            在您的 application.properties 文件中 -

            /src/main/resources/application.properties

            把端口号改成这样 -

            server.port=8181

            或者,您可以在执行 jar 文件时提供替代端口号 - java -jar resource-server/build/libs/resource-server.jar --server.port=8888

            【讨论】:

              【解决方案12】:

              您可以在 IDE 中配置另一个端口号 /src/main/resources/application.properties

              server.port=8081

              否则右键单击 IDE 控制台选项卡并选择 Terminate/Disconnect All

              【讨论】:

                【解决方案13】:

                在我的情况下,Oracle TNS 服务使用端口 8080,发现以管理员身份运行命令“netstat - anob”。只需使用 Windows 开始菜单中的 Shutdown Database 来停止该服务,就可以毫无问题地启动 SpringBoot 应用程序。

                此外,如果您无法找出哪个应用程序正在使用 8080 端口并且只想运行 SprintBoot 应用程序,您可以单击 Run As... 并在 VM 参数中输入: -Dserver.port=0(这将选择任何随机可用端口)或者您可以具体如下:-Dserver.port=8081

                希望对你有帮助。

                【讨论】:

                • 我尝试更改我的 -Dserver.port=0 并使用同时启动的两个应用程序进行测试。现在都在不同的端口打开
                【解决方案14】:

                您可以按照以下步骤解决此问题:

                1. 右键单击您正在运行的项目。
                2. 点击选项中的Run asRun Configurations
                3. 将打开一个新的运行配置。在 Spring Boot 选项卡 下查看 Override properties
                4. 将属性值对添加为server.port=8181,或您选择的任何其他端口。这将覆盖默认端口 8080

                【讨论】:

                  【解决方案15】:

                  这真是个老问题。也许这很有用。专注于您的标题问题,这就是我启动应用程序然后可以轻松关闭它们的方式。如上所述更改要启动的每个应用程序的端口号。

                  application.properties

                  #using curl -X POST localhost:8080/actuator/shutdown to avoid:
                  #netstat -ano | find "8080"
                  #taskkill /F /PID xxxx (xxxx stands for PID)
                  management.endpoints.web.exposure.include=*
                  management.endpoint.shutdown.enabled=true
                  endpoints.shutdown.enabled=true
                  

                  添加这个依赖:

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

                  现在你可以轻松击落

                  curl -X POST localhost:8080/actuator/shutdown
                  

                  【讨论】:

                    【解决方案16】:

                    在控制台中右键单击,然后单击终止/断开所有选项。

                    单击控制台窗口右上角的“显示选定的控制台”图标,然后选择并终止保持端口静止的控制台。

                    【讨论】:

                      【解决方案17】:

                      我一直在寻找适用于 Windows 的解决方案,但没有找到。 最后,发现有一个悬空的 Java 应用程序使用该端口。可能是早期的spring应用实例,结束了流程。

                      我使用了tcpview from Microsoft。它显示使用您计算机上哪个端口的服务/应用程序。

                      您可以结束该过程。完成了!

                      【讨论】:

                        【解决方案18】:

                        这是因为端口已经在后台运行了。所以你可以重启eclipse再试一次。 要么 打开文件 application.properties 并将“server.port”的值更改为其他值,例如:- 8000/8181

                        【讨论】:

                          【解决方案19】:

                          我通过停止应用程序(Eclipse 中的红色方块)在再次运行之前解决了这个问题。 如果您不停止它,应用程序将处于运行模式,因此仍使用端口。

                          【讨论】:

                            【解决方案20】:

                            您有另一个进程正在侦听端口 8080,这是 Spring Boot 的 Web 支持使用的默认端口。您要么需要停止该进程,要么将您的应用配置为侦听另一个端口。

                            您可以通过将 server.port=4040(例如)添加到 src/main/resources/application.properties

                            来更改端口配置

                            【讨论】:

                              【解决方案21】:

                              基本上默认服务器通常在 8080 端口在后台运行。 打开 services.msc 并停止 tomcat 服务器并尝试再次运行 spring boot 应用程序。

                              【讨论】:

                                【解决方案22】:

                                在 Eclipse 中,如果安装了 Spring Tool Suite,您可以转到 Boot Dashboard 并在资源管理器中展开本地,然后右键单击端口 8080 上运行的应用程序并在重新运行之前将其停止你的申请。

                                【讨论】:

                                  【解决方案23】:

                                  我尝试在以下文件中更改端口号 - /src/main/resources/application-prod.yml

                                  在这个文件中我做了这个改变:

                                  服务器: 端口:8100(或任何你想要的)

                                  我希望这对你有好处

                                  【讨论】:

                                    【解决方案24】:

                                    刚刚遇到同样的问题。

                                    最后我发现在 8080 上运行的进程被其他用户拥有,例如 root。这导致我(用户开发人员)无法通过lsof -i :8080lsof -t -i :8080 -s TCP:LISTEN 找到它。

                                    【讨论】:

                                      【解决方案25】:

                                      关闭应用,切换到新端口后重启:

                                      ${port:8181}
                                      

                                      您可以使用任何新的未使用端口。在这里,我使用了 8181 端口。

                                      【讨论】:

                                      • @Bruce 这怎么不试图提供答案?我看到了一个明确的尝试:关闭应用程序;更改端口;并重新启动它。这可能是完全错误的,但这并不意味着它不是试图回答。
                                      【解决方案26】:

                                      我遇到了同样的问题,即 协议处理程序启动失败。原因是端口已在使用中。我发现端口是否在使用中。它是。因此,我终止了在该端口上运行的进程并重新启动了我的 Spring Boot 应用程序。它奏效了。 :)

                                      【讨论】:

                                        猜你喜欢
                                        • 2016-04-20
                                        • 2020-04-15
                                        • 2019-02-02
                                        • 2017-07-07
                                        • 2016-05-02
                                        • 1970-01-01
                                        • 2013-04-16
                                        • 2021-04-24
                                        • 1970-01-01
                                        相关资源
                                        最近更新 更多