两个springboot项目如何部署在同一个服务上,两个spring启动应用程序部署在同一台服务器上...

现在有两个spring boot的maven项目,需要部署到同一个外部的服务上(tomcat),他们都包含spring-boot-starter-actuator(健康检查)的依赖,但是出现下面的异常

我有多个spring引导应用程序(maven项目),其中包含“spring-boot-starter-actuator”依赖项,用于检查每个应用程序的运行状况。在tomcat服务器中部署这两个应用程序时,我会得到以下异常 

2016-05-02 22:30:44.627 ERROR 12734 --- [ost-startStop-3] o.s.b.a.e.jmx.EndpointMBeanExporter : Could not register MBean for endpoint [dumpEndpoint] org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [org.springframework.boot.actuate.endpoint.jmx.DataEndpointMBean@67e7c413] with key 'dumpEndpoint'; nested exception is javax.management.InstanceAlreadyExistsException: org.springframework.boot:type=Endpoint,name=dumpEndpoint at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:625) ~[spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter.registerEndpoint(EndpointMBeanExporter.java:182) [spring-boot-actuator-1.3.0.RELEASE.jar:1.3.0.RELEASE] at org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter.locateAndRegisterEndpoints(EndpointMBeanExporter.java:162) [spring-boot-actuator-1.3.0.RELEASE.jar:1.3.0.RELEASE] at org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter.doStart(EndpointMBeanExporter.java:153) [spring-boot-actuator-1.3.0.RELEASE.jar:1.3.0.RELEASE] at org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter.start(EndpointMBeanExporter.java:276) [spring-boot-actuator-1.3.0.RELEASE.jar:1.3.0.RELEASE] at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:173) [spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:51) [spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:346) [spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:149) [spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:112) [spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:851) [spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:140) [spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:540) [spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) [spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752) [spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE] at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:347) [spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:295) [spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE] at org.springframework.boot.context.web.SpringBootServletInitializer.run(SpringBootServletInitializer.java:149) [spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE] at org.springframework.boot.context.web.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:129) [spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE] at org.springframework.boot.context.web.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:85) [spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE] at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:175) [spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5155) [catalina.jar:8.0.21] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:8.0.21] at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725) [catalina.jar:8.0.21] at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701) [catalina.jar:8.0.21] at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717) [catalina.jar:8.0.21] at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:940) [catalina.jar:8.0.21] at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1738) [catalina.jar:8.0.21] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0] at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0] at java.lang.Thread.run(Thread.java:744) [na:1.8.0] Caused by: javax.management.InstanceAlreadyExistsException: org.springframework.boot:type=Endpoint,name=dumpEndpoint at com.sun.jmx.mbeanserver.Repository.addMBean(Repository.java:437) ~[na:1.8.0] at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerWithRepository(DefaultMBeanServerInterceptor.java:1898) ~[na:1.8.0] at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean(DefaultMBeanServerInterceptor.java:966) ~[na:1.8.0] at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(DefaultMBeanServerInterceptor.java:900) ~[na:1.8.0] at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:324) ~[na:1.8.0] at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:522) ~[na:1.8.0] at org.springframework.jmx.support.MBeanRegistrationSupport.doRegister(MBeanRegistrationSupport.java:195) ~[spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.jmx.export.MBeanExporter.registerBeanInstance(MBeanExporter.java:678) ~[spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:621) ~[spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE] ... 32 common frames omitted

//***************************************************************************************************************************************************************************

解决办法

 

需要为每个项目配置JMX的域,修改application.properties中的属性spring.jmx.default-domain = applicationname

您可以在application.properties中使用以下属性为每个应用程序配置JMX域(例如,使用应用程序名称作为域):

spring.jmx.default-domain=applicationname

这为Spring添加的所有JMX端点配置了域。

endpoints.jmx.domain=applicationname

这仅为执行器端点配置JMX域。

然后这将防止在不同的应用程序中使用相同名称的JMX bean冲突,因为该域将被添加到JMX名称中。

 

转载于:https://www.cnblogs.com/Nikola/p/8823915.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot 项目部署服务器上通常可以有以下几种方法: 1. 打包成可执行的 JAR 文件 使用 Maven 或 Gradle 将 Spring Boot 项目打包成可执行的 JAR 文件,然后将该文件上传到服务器上,使用命令行运行该 JAR 文件即可启动 Spring Boot 应用。例如: ``` java -jar app.jar ``` 2. 打包成 WAR 文件 如果需要将 Spring Boot 应用部署到外部 Web 服务器中,可以将其打包成 WAR 文件。在 Maven 或 Gradle 中,只需要将 packaging 属性设置为 war 即可。然后将 WAR 文件部署到 Web 服务器中即可。 3. 使用 Docker 镜像 使用 Docker 将 Spring Boot 应用打包成镜像,然后在服务器上运行该镜像。这种方法可以快速部署应用程序,并且可以保证应用程序的可移植性和一致性。 4. 使用云服务部署Spring Boot 应用部署到云服务器上,例如 AWS、Azure、Google Cloud 等云服务提供商。这种方法可以快速部署应用程序,并且可以根据需要进行自动扩展和负载均衡。 当部署 Spring Boot 应用程序服务器上时,一些注意事项包括: 1. 确保服务器上已经安装了 Java 运行环境,可以使用命令 java -version 检查。 2. 配置应用程序的端口号,确保可以从外部访问应用程序。可以在 application.properties 或 application.yml 文件中配置端口号。 3. 配置数据库连接等外部资源的信息,确保应用程序可以正常访问这些资源。 4. 配置应用程序日志的路径和级别,以便进行调试和错误排查。 5. 确保应用程序的安全性,例如禁止使用默认的管理员账户和密码等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值