启动Spring应用程序地址已在使用中


97

我在启动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,但问题仍然存在

我发现这篇文章:

从Maven启动时,Tomcat的备用端口(不是8080)吗?

但是在启动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以获取使用的端口及其各自的processID的完整列表。在启动tomcat之前,从那里验证端口是否已闲置
Saif Asif 2013年

是的,我的端口8181是免费的
Ajouve 2013年

1
检查默认端口(8080)是否正在运行。在Windows中,使用> netstat -a -o -n,然后搜索端口号是否正在运行....如果正在运行,请记下对应的pid。taskkill / f / pid {pidno}
Sagar Rout

同样,配置文件中的IP错误会导致此异常。
Xaqron '17

Answers:


108

Spring Boot默认情况下使用嵌入式Tomcat,但是在不使用的情况下,对它的处理方式有所不同tomcat-maven-plugin。例如,要更改端口使用--server.port参数:

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

更新。或者把server.port=8181application.properties(或application.yml)。


2
是否可以在配置中进行设置?例如使用注释?
Daniil Shevelev 2014年

65
server.port=8181到您的application.properties文件还应该工作。
MarcinZajączkowski14年

不要忘记清洁和建造...这也有帮助
cheenbabes 2014年

4
application.properties文件的一个更好的选择是包括具有覆盖功能server.port = $ {port:8181}的默认设置
Shawn Vader 2015年

1
非常感谢男人!我整天都在搜索该解决方案,在添加--server.port = 8181之后就解决了。谢谢
gsiradze 2015年

46

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

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

再次启动该应用程序。


1
我必须使用此命令才能使其在Mac上运行:sudo lsof -n -P | grep LISTEN。Mac将提示您在使用sudo时输入密码。
西蒙(Simon)

感谢您在这里回答。仅此解决方案可与IntelliJ
AMIC MING一起使用

30

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

server.port = 8181


@Junchen Lui那是因为这只是一种解决方法。如果一直这样做,将会有很多未使用的tomcat运行。最好首先解决错误。
斯廷普森猫,

大坝,这真的工作没有配置任何XML或设置projecto
咳咳-迭戈·马托斯


4

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


4

Spring Tool Suite和停止应用程序按钮的图像

就我而言,在服务器窗口中查看仅显示了我从未在该项目中使用过的tomcat服务器。我的SpringBoot项目使用了嵌入式tomcat服务器,并且在我的应用程序完成时它没有停止。我用红色箭头指示的此按钮将停止应用程序和Tomcat服务器,因此,下次运行该应用程序时,不会出现以下错误:Tomcat实例已在端口8080上运行。

实际错误消息:

验证连接器的配置,确定并停止正在端口8080上侦听的所有进程,或将此应用程序配置为在另一个端口上侦听。

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

现在,在本教程中,我将研究一种在我的SpringBoot Consuming Rest应用程序完成时关闭所有服务的方法https://spring.io/guides/gs/using-rest/

弹簧靴


3

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

如果正在使用端口8080,请将侦听端口更改为8181。

如果使用IDEA,请修改开始配置,运行->编辑配置, 在此处输入图像描述

如果您使用mvn spring-boot,请使用以下命令:

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

如果使用java -jar,则使用命令:

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

2

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

  • 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     

1
这对我有用。在Spring Boot 2.0.3.RELEASE中,management.port密钥被替换为management.server.port
biniam

tomcat.jvmroute = 5478帮助我运行了应用程序的两个实例以及server.port = 18181
Ritesh K


2

在您的application.properties文件中-

/ src / main / resources / application.properties

将端口号更改为类似的内容-

server.port = 8181

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


2

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

server.port = 8081

否则,右键单击“ IDE 控制台”选项卡,然后选择“ 终止/断开所有连接”


1

在我的情况下,Oracle TNS Service使用端口8080,发现以管理员身份运行命令“ netstat-anob”。只需使用Windows开始菜单中的Shutdown Database即可停止该服务,并且能够启动SpringBoot应用程序而没有任何问题。

另外,如果您无法找到哪个应用程序正在使用8080端口,而只想运行SprintBoot应用程序,则可以单击Run As ...,然后在VM参数中输入:-Dserver.port = 0(这将随机选择可用端口),也可以像以下这样特定:-Dserver.port = 8081

希望能帮助到你。


我尝试更改-Dserver.port = 0并测试了同时启动的两个应用程序。现在两者都在不同的港口开放
hnahak

1

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

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

1

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

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

1

在控制台中右键单击,然后单击“终止/全部断开连接”选项。

要么

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


1

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

解决方案1:释放端口

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

netstat -pnltu | grep -i "8080"

上述命令的输出将类似于:

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

然后,您可以使用其processid轻松终止该进程:

kill 20674

在Windows机器上找到一个processid使用netstat -ano -p tcp |find "8080"。要取消使用进程taskkill /F /PID 1234(请输入1234,而不是输入已创建的processid)。

解决方案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...

1

我一直在寻找Windows的解决方案,但没有找到任何解决方案。最后,弄清楚使用该端口存在一个悬空的Java应用程序。也许这是spring应用程序的较早实例,并结束了该过程。

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

在此处输入图片说明

您可以结束该过程。并做了!


1

这是因为该端口已经在后台运行。因此,您可以重新启动Eclipse并重试。或打开文件application.properties,并将“ server.port”的值更改为其他值,例如:8000/8181


0

关闭应用程序,然后在更改为新端口后重新启动它:

${port:8181}

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


@Bruce如何不尝试提供答案?我看到了一个明确的尝试:关闭应用程序;更改端口;并重新启动它。这可能是完全错误的,但这并不意味着它不是要尝试的答案。
撤消

0

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


0

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

您可以通过将server.port = 4040(例如)添加到src / main / resources / application.properties来更改端口配置。


0

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


0

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


0

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

在此文件中,我进行了更改:

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

我希望这对您有用


-1

我遇到了同样的问题,即协议处理程序启动失败。原因是端口已在使用中。我发现端口是否在使用中。它是。因此,我杀死了该端口上正在运行的进程,然后重新启动了我的spring boot应用程序。而且有效。:)

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.