开发者社区> 问答> 正文

在Spring Boot 1.2.1 添加druid-spring-boot-starter 1.1

2017-08-10 16:03:06.826 [main] INFO o.s.b.c.e.AnnotationConfigEmbeddedWebApplicationContext - Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@11846d13: startup date [Thu Aug 10 16:02:57 CST 2017]; root of context hierarchy 2017-08-10 16:03:06.828 [main] WARN o.s.b.c.e.AnnotationConfigEmbeddedWebApplicationContext - Exception thrown from ApplicationListener handling ContextClosedEvent java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@11846d13: startup date [Thu Aug 10 16:02:57 CST 2017]; root of context hierarchy at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:344) [spring-context-4.1.4.RELEASE.jar:4.1.4.RELEASE] at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:331) [spring-context-4.1.4.RELEASE.jar:4.1.4.RELEASE] at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:869) [spring-context-4.1.4.RELEASE.jar:4.1.4.RELEASE] at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.doClose(EmbeddedWebApplicationContext.java:150) [spring-boot-1.2.1.RELEASE.jar:1.2.1.RELEASE] at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:836) [spring-context-4.1.4.RELEASE.jar:4.1.4.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:343) [spring-boot-1.2.1.RELEASE.jar:1.2.1.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:961) [spring-boot-1.2.1.RELEASE.jar:1.2.1.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:950) [spring-boot-1.2.1.RELEASE.jar:1.2.1.RELEASE] at com.vantoo.Application.main(Application.java:55) [classes/:na] 2017-08-10 16:03:06.829 [main] WARN o.s.b.c.e.AnnotationConfigEmbeddedWebApplicationContext - Exception thrown from LifecycleProcessor on context close java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@11846d13: startup date [Thu Aug 10 16:02:57 CST 2017]; root of context hierarchy at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:357) [spring-context-4.1.4.RELEASE.jar:4.1.4.RELEASE] at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:877) [spring-context-4.1.4.RELEASE.jar:4.1.4.RELEASE] at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.doClose(EmbeddedWebApplicationContext.java:150) [spring-boot-1.2.1.RELEASE.jar:1.2.1.RELEASE] at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:836) [spring-context-4.1.4.RELEASE.jar:4.1.4.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:343) [spring-boot-1.2.1.RELEASE.jar:1.2.1.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:961) [spring-boot-1.2.1.RELEASE.jar:1.2.1.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:950) [spring-boot-1.2.1.RELEASE.jar:1.2.1.RELEASE] at com.vantoo.Application.main(Application.java:55) [classes/:na] Exception in thread "main" java.lang.IllegalStateException: Could not evaluate condition on com.alibaba.druid.spring.boot.autoconfigure.stat.DruidFilterConfiguration#statFilter due to internal class not found. This can happen if you are @ComponentScanning a springframework package (e.g. if you put a @ComponentScan in the default package by mistake) at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:51) at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:102) at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:185) at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:148) at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:124) at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:318) at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:239) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:254) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:606) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:462) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691) at org.springframework.boot.SpringApplication.run(SpringApplication.java:321) at org.springframework.boot.SpringApplication.run(SpringApplication.java:961) at org.springframework.boot.SpringApplication.run(SpringApplication.java:950) at com.vantoo.Application.main(Application.java:55) Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/web/servlet/ServletRegistrationBean at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2625) at java.lang.Class.getDeclaredMethods(Class.java:1868) at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:571) at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:490) at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:474) at org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:534) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:677) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:621) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:591) at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1397) at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:968) at org.springframework.boot.autoconfigure.condition.BeanTypeRegistry$OptimizedBeanTypeRegistry.addBeanTypeForNonAliasDefinition(BeanTypeRegistry.java:257) at org.springframework.boot.autoconfigure.condition.BeanTypeRegistry$OptimizedBeanTypeRegistry.addBeanType(BeanTypeRegistry.java:246) at org.springframework.boot.autoconfigure.condition.BeanTypeRegistry$OptimizedBeanTypeRegistry.getNamesForType(BeanTypeRegistry.java:227) at org.springframework.boot.autoconfigure.condition.OnBeanCondition.collectBeanNamesForType(OnBeanCondition.java:154) at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getBeanNamesForType(OnBeanCondition.java:143) at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchingBeans(OnBeanCondition.java:115) at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchOutcome(OnBeanCondition.java:90) at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:45) ... 16 more Caused by: java.lang.ClassNotFoundException: org.springframework.boot.web.servlet.ServletRegistrationBean at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) ... 36 more

原提问者GitHub用户vantoo

展开
收起
山海行 2023-07-05 20:47:01 51 0
3 条回答
写回答
取消 提交回答
  • 在Spring Boot 1.2.1中添加druid-spring-boot-starter 1.1并不是一个具体的问题,而更像是一个需求或操作步骤。如果您想了解如何在Spring Boot 1.2.1中添加druid-spring-boot-starter 1.1,请按照以下步骤进行操作:

    1. 打开项目的pom.xml文件。 2. 在<dependencies>标签内添加以下依赖项:    xml    <dependency>        <groupId>com.alibaba</groupId>        <artifactId>druid-spring-boot-starter</artifactId>        <version>1.1.10</version>    </dependency>     3. 保存并关闭pom.xml文件。 4. 使用构建工具(如Maven)重新构建项目,以便下载并添加新的依赖项。 5. 在您的Spring Boot应用程序中配置Druid连接池。您可以通过在application.properties文件中添加以下属性来完成配置:    ```properties    # 数据源配置    spring.datasource.url=jdbc:mysql://localhost:3306/db_name    spring.datasource.username=username    spring.datasource.password=password    spring.datasource.driver-class-name=com.mysql.jdbc.Driver        # Druid连接池配置    spring.datasource.type=com.alibaba.druid.pool.DruidDataSource    spring.datasource.initialSize=5    spring.datasource.minIdle=5    spring.datasource.maxActive=20    spring.datasource.testOnBorrow=true    spring.datasource.validationQuery=SELECT 1

       # 配置Druid监控页面访问路径    spring.datasource.druid.stat-view-servlet.enabled=true    spring.datasource.druid.stat-view-servlet.url-pattern=/druid/*    ```    您可以根据需要修改这些属性来满足您的实际需求。

    完成以上步骤后,您的Spring Boot应用程序将使用Druid作为连接池。请确保您已经正确配置了数据库信息和Druid的相关属性。如果遇到任何问题,请及时提问并提供详细的错误信息,以便我们能够更好地帮助您解决问题。

    2023-07-30 14:35:12
    赞同 展开评论 打赏
  • 北京阿里云ACE会长

    如果您想在Spring Boot 1.2.1中使用Druid连接池,可以添加druid-spring-boot-starter 1.1依赖。Druid-Spring-Boot-Starter是一个用于在Spring Boot应用程序中集成Druid连接池的官方Starter,它提供了自动配置和可选的监控功能,使得在应用程序中使用Druid变得更加简单和方便。

    2023-07-30 13:26:22
    赞同 展开评论 打赏
  • 建议升级 Spring Boot 的版本至1.4.X以上版本(推荐使用1.5.X的当前稳定发行版本),Spring Boot 1.2.1确实太老了(2015.1发布),不支持使用ServletRegistrationBean的方式注册 Servlet,进而导致的该问题 。

    原回答者GitHub用户lihengming

    2023-07-06 11:46:21
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载

相关实验场景

更多