Spring Boot几种启动问题的解决方案

  使用Spring Boot以来,遇到和解决过好几次不同的项目启动问题,大多数事故起于错误的配置和依赖。因此,本文用于汇总这些问题,以及提供相应的解决方案,帮助大家更快的定位和排除故障。

1. Unregistering JMX-exposed beans on shutdown

  项目中没有添加spring-boot-starter-web模块依赖,在启动 Application 运行过程中会出现这个错误。

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

2018-05-02 18:32:49.445  INFO 33160 --- [           main] cn.mariojd.demo.DemoApplication          : Starting DemoApplication on Mario with PID 33160 (started by jd in D:\IntelliJ IDEA\projects\test)
2018-05-02 18:32:49.451  INFO 33160 --- [           main] cn.mariojd.demo.DemoApplication          : No active profile set, falling back to default profiles: default
2018-05-02 18:32:49.542  INFO 33160 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@17211155: startup date [Wed May 02 18:32:49 CST 2018]; root of context hierarchy
2018-05-02 18:32:50.115  INFO 33160 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-05-02 18:32:50.128  INFO 33160 --- [           main] cn.mariojd.demo.DemoApplication          : Started DemoApplication in 1.01 seconds (JVM running for 1.83)
... end SpringApplication.run()
2018-05-02 18:32:50.129  INFO 33160 --- [       Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@17211155: startup date [Wed May 02 18:32:49 CST 2018]; root of context hierarchy
2018-05-02 18:32:50.130  INFO 33160 --- [       Thread-2] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown

  解决方案,引入spring-boot-starter-web模块

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

  网上大多数的解决方案是通过添加spring-boot-starter-tomcat依赖来解决,但实测证明此方法不可行。

2. Cannot determine embedded database driver class for database type NONE

  项目中添加了spring-boot-starter-data-jpa模块依赖,而且没有配置数据源连接信息的情况下,启动 Application 过程中会出现该错误,原因是Spring Boot在启动时会自动注入数据源和配置JPA。


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

2018-05-02 19:49:13.640  INFO 37652 --- [           main] cn.mariojd.demo.DemoApplication          : Starting DemoApplication on Mario with PID 37652 (started by jd in D:\IntelliJ IDEA\projects\test)
2018-05-02 19:49:13.643  INFO 37652 --- [           main] cn.mariojd.demo.DemoApplication          : No active profile set, falling back to default profiles: default
2018-05-02 19:49:13.692  INFO 37652 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@62fdb4a6: startup date [Wed May 02 19:49:13 CST 2018]; root of context hierarchy
2018-05-02 19:49:15.150  INFO 37652 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$4ad697b] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-05-02 19:49:15.433  INFO 37652 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2018-05-02 19:49:15.460  INFO 37652 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-05-02 19:49:15.461  INFO 37652 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.29
2018-05-02 19:49:15.564  INFO 37652 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-05-02 19:49:15.564  INFO 37652 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1876 ms
2018-05-02 19:49:15.679  INFO 37652 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2018-05-02 19:49:15.682  INFO 37652 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-05-02 19:49:15.682  INFO 37652 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-05-02 19:49:15.682  INFO 37652 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-05-02 19:49:15.683  INFO 37652 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2018-05-02 19:49:15.717  WARN 37652 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Tomcat.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
2018-05-02 19:49:15.719  INFO 37652 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2018-05-02 19:49:15.765  INFO 37652 --- [           main] utoConfigurationReportLoggingInitializer : 

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-05-02 19:49:15.791 ERROR 37652 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

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

Description:

Cannot determine embedded database driver class for database type NONE

Action:

If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).


Process finished with exit code 1

  • 解决方案1,移除spring-boot-starter-data-jpa模块依赖;
  • 解决方案2,将启动类注解@SpringBootApplication修改如下;
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class,DataSourceTransactionManagerAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
  • 解决方案3,在配置文件中添加数据库连接信息。
spring:
  datasource:
    url: xxx
    username: xxx
    password: xxx
### 回答1: Spring Boot 是一种快速构建企业级应用的框架。在建立个人博客系统时,它可以帮助开发人员快速构建博客系统的后端架构,并使用其内置的自动配置功能为博客系统提供各种功能,如数据持久化、安全认证、文件上传和下载等。 使用 Spring Boot 开发个人博客系统可以解决以下问题: 1. 快速构建后端架构:Spring Boot 内置了许多常用的框架和库,可以帮助开发人员快速构建出博客系统的后端架构。 2. 自动配置功能:Spring Boot 可以自动配置许多常用的功能,如数据库连接、安全认证、文件上传下载等,使开发人员可以专注于开发业务逻辑。 3. 简化部署流程:Spring Boot 可以使用内置的 tomcat 服务器进行部署,简化了部署流程。 4. 提供企业级应用所需的功能:Spring Boot 提供了许多企业级应用所需的功能,如安全认证、数据持久化等,可以使个人博客系统更加完善。 ### 回答2: Spring Boot 个人博客系统是一款基于Spring Boot框架开发的博客系统,它能够解决以下问题: 1. 快速开发:Spring Boot框架提供了许多开箱即用的功能和组件,极大地简化了开发流程。其中包括自动配置、内嵌服务器、自动项目构建等,可以快速搭建一个功能完善的博客系统。 2. 简化部署:Spring Boot使用嵌入式服务器,如Tomcat或Jetty,可以将应用程序打包成一个可执行的JAR文件,只需执行一条命令即可启动应用程序,无需额外部署和配置服务器,极大地简化了部署流程。 3. 高度可定制:Spring Boot提供了丰富的配置选项和扩展点,可以根据个人需求进行灵活的定制。可通过配置文件进行自定义配置,也可以通过扩展Spring Boot的自动配置机制来引入额外的功能。 4. 高效性能:Spring Boot集成了很多优化的组件,如Spring MVC、Spring Data、Spring Security等,能够提供高性能的Web服务。此外,Spring Boot还支持异步处理、缓存机制等,可以进一步提升系统的响应速度和并发能力。 5. 微服务支持:Spring Boot天生支持构建微服务架构,可以将一个大型的博客系统拆分为多个小型的服务,每个服务专注于特定的功能,提高了系统的可维护性和可扩展性。 6. 生态系统丰富:Spring BootSpring生态系统的一部分,可以与其他Spring项目无缝集成,如Spring Cloud、Spring Security等。同时,Spring Boot还支持各种第三方库和工具的集成,如数据库、缓存、消息队列等。 综上所述,Spring Boot个人博客系统不仅能够提供快速开发和部署的能力,还能够提供高度定制性、高效性能、微服务支持以及丰富的生态系统,为个人博客的开发者提供了一个可靠和便捷的解决方案。 ### 回答3: Spring Boot个人博客系统是一种基于Spring Boot框架开发的博客系统,它能够解决以下几个问题: 1. 快速开发:Spring Boot个人博客系统采用了Spring Boot框架,这个框架提供了很多开箱即用的特性,如自动配置、快速构建等,极大地减少了开发者的开发时间和精力,使得开发者能够更专注于业务逻辑的实现,从而实现快速开发。 2. 简化配置:Spring Boot个人博客系统采用了约定优于配置的原则,大部分的配置都可以通过少量的配置文件完成,大大简化了系统的配置工作。同时,Spring Boot还有一个在线配置工具——Spring Initializr,可以在线生成项目的初始配置,进一步减轻了配置的负担。 3. 整合丰富的开源组件:Spring Boot个人博客系统内置了许多常用的开源组件,如Thymeleaf模板引擎、Spring Data JPA、Spring Security等,这些组件都经过了充分的测试和验证,能够提供稳定、高效的功能实现。同时,Spring Boot还提供了自动配置功能,可以自动根据项目的依赖关系自动配置相关的组件,大大简化了整合的工作。 4. 响应式设计:Spring Boot个人博客系统支持响应式设计,可以很方便地适配不同的终端设备,如PC、手机、平板等,提供更好的用户体验。 总之,Spring Boot个人博客系统通过快速开发、简化配置、整合丰富的开源组件和响应式设计等特性,能够解决开发者在开发个人博客系统时遇到的瓶颈,提高开发效率,降低开发成本。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值