spring-boot启动失败 Unregistering JMX-exposed beans on shutdown的三种解决方法

寄语:

    学习的路途各种文章只是给你提供一个思路,适不适合自己还是要自己去总结,以下是我的项目遇到同样的问题但是尝试了多种方法,未果,特将这些方法总结如下,希望过往僧侣能尽快取得真经!

这是有问题,也是创建SpringBoot项目后原始的pom.xml文件依赖

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

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter</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>
        </dependencies>

这是启动报的错误:

 .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.5.4.RELEASE)

2018-07-31 10:13:41.552  INFO 6588 --- [           main] t.w.s.s.SpringbootdemoApplication        : Starting SpringbootdemoApplication on Action with PID 6588 (D:\WorkSpace_Idea\top.wj\springbootdemo\target\classes started by hp in D:\WorkSpace_Idea\top.wj)
2018-07-31 10:13:41.552  INFO 6588 --- [           main] t.w.s.s.SpringbootdemoApplication        : No active profile set, falling back to default profiles: default
2018-07-31 10:13:41.568  INFO 6588 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@11c20519: startup date [Tue Jul 31 10:13:41 CST 2018]; root of context hierarchy
2018-07-31 10:13:41.896  INFO 6588 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-07-31 10:13:41.911  INFO 6588 --- [           main] t.w.s.s.SpringbootdemoApplication        : Started SpringbootdemoApplication in 0.499 seconds (JVM running for 0.922)
2018-07-31 10:13:41.911  INFO 6588 --- [       Thread-3] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@11c20519: startup date [Tue Jul 31 10:13:41 CST 2018]; root of context hierarchy
2018-07-31 10:13:41.911  INFO 6588 --- [       Thread-3] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown

Process finished with exit code 0

解决方法    一、

网上普罗大众的解决方案都是在pom.xml文件中添加

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

注意:

     这里要把<scope>provided</scope>注释掉,或者把provided改为compire

原因:该依赖默认scope 为provided,编译直接运行后,无法确定一个容器,项目无法启动。

在POM 4中,<dependency>中还引入了<scope>,它主要管理依赖的部署。目前<scope>可以使用5个值:
    * compile,缺省值,适用于所有阶段,会随着项目一起发布。 
    * provided,类似compile,期望JDK、容器或使用者会提供这个依赖。如servlet.jar。 
    * runtime,只在运行时使用,如JDBC驱动,适用运行和测试阶段。 
    * test,只在测试时使用,用于编译和运行测试代码。不会随项目发布。 
    * system,类似provided,需要显式提供包含依赖的jar,Maven不会在Repository中查找它。

但是这里就有一个问题,希望知道的同学留言交流。

//TODO

问题:SpringBoot是使用的内置tomcat,为什么还要引入来解决tomcat的问题?是SpringBoot的漏洞还是有其他原因?

解决方法   二:

因为我的项目创建以后<parent>就直接继承好了

        <parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.0.3.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>

那么问题来了,这里的版本是2.0.3.RELEASE如果把版本号修改了,代码提示提示不出该版本号

把版本号降一级降到Idea可以提示的版本号,问题解决!

解决方法   三、

在pom.xml文件中引入

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

这个是因为创建SpringBoot项目时,我勾选的是SQL,所以缺少web的依赖

亲测有效,这三种方法可独立操作也可并用!问题是根据自己的问题来解决!个人随笔,只做记录,希望能帮到各位!

  • 9
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值