bug-6-Error creating bean ...

话说:

各位读者盆友,上一篇博客SSM通过Maven搭建完毕,后台测试成功,部署到Tomcat后报错如下,欢迎评论留言,解决问题者私信我,悬赏红包!(哈哈,后面自己发现了.. )

之所以要记录这个Bug,是因为困扰得我是无比郁闷,新建了项目,还是报错。最后灵感一现,搞定!

报错信息:

ERROR SqlExceptionHelper Cannot create PoolableConnectionFactory (Unknown database 'meice_blog')
    ERROR ContextLoader Context initialization failed
 org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'blogAction': Unsatisfied dependency expressed through field 'blogService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blogService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blogDao': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in URL [file:/D:/Program%20Files/apache-tomcat-8.5.24/webapps/ROOT/WEB-INF/classes/spring.xml]: Invocation of init method failed; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:581)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91)
    at 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blogService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blogDao': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in URL [file:/D:/Program%20Files/apache-tomcat-8.5.24/webapps/ROOT/WEB-INF/classes/spring.xml]: Invocation of init method failed; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:321)

    ... 28 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blogDao': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in URL [file:/D:/Program%20Files/apache-tomcat-8.5.24/webapps/ROOT/WEB-INF/classes/spring.xml]: Invocation of init method failed; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution
    at 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in URL [file:/D:/Program%20Files/apache-tomcat-8.5.24/webapps/ROOT/WEB-INF/classes/spring.xml]: Invocation of init method failed; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapa
cessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:318)
    ... 52 more
Caused by: org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)

Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Unknown database 'meice_blog')

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'meice_blog'
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

三月 11, 2018 3:11:05 上午 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class [org.springframework.web.context.ContextLoaderListener]
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'blogAction': Unsatisfied dependency expressed through field 'blogService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blogService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blogDao': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in URL [file:/D:/Program%20Files/apache-tomcat-8.5.24/webapps/ROOT/WEB-INF/classes/spring.xml]: Invocation of init method failed; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution
    at ans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
    at 

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blogService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blogDao': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in URL [file:/D:/Program%20Files/apache-tomcat-8.5.24/webapps/ROOT/WEB-INF/classes/spring.xml]: Invocation of init method failed; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blogDao': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in URL [file:/D:/Program%20Files/apache-tomcat-8.5.24/webapps/ROOT/WEB-INF/classes/spring.xml]: Invocation of init method failed; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:321)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapabl
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in URL [file:/D:/Program%20Files/apache-tomcat-8.5.24/webapps/ROOT/WEB-INF/classes/spring.xml]: Invocation of init method failed; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapab
Caused by: org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution

    ... 64 more
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Unknown database 'meice_blog')

    ... 81 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'meice_blog'
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
    at com.mysql.jdbc.Util.getInstance(Util.java:387)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:939)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814)

三月 11, 2018 3:11:05 上午 org.apache.catalina.core.StandardContext startInternal
严重: One or more listeners failed to start. Full details will be found in the appropriate container log file
三月 11, 2018 3:11:05 上午 org.apache.catalina.core.StandardContext startInternal
严重: Context [] startup failed due to previous errors
三月 11, 2018 3:11:05 上午 org.apache.catalina.core.ApplicationContext log
信息: Closing Spring root WebApplicationContext
三月 11, 2018 3:11:05 上午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc
警告: The web application [ROOT] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
三月 11, 2018 3:11:05 上午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
警告: The web application [ROOT] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.lang.Object.wait(Native Method)
 java.lang.ref.ReferenceQueue.remove(Unknown Source)
 com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:43)
三月 11, 2018 3:11:05 上午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deployment of web application directory [D:\Program Files\apache-tomcat-8.5.24\webapps\ROOT] has finished in [14,844] ms
三月 11, 2018 3:11:05 上午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["http-nio-8088"]
三月 11, 2018 3:11:05 上午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["ajp-nio-8010"]
三月 11, 2018 3:11:05 上午 org.apache.catalina.startup.Catalina start
信息: Server startup in 27082 ms

当然笔者中间把部分赘余报错信息删去。

这里最奇葩的是:我整个项目中哪里有什么**blogAction,blogService,根本没有这些东东,哪里出现的这些错误呢?找都没法找,因为根本就不存在啊。而且哪里涉及到**Hibernate了?竟然报错rg.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution,你说古怪不古怪!!

元芳,你说奇怪不?

而且,我重建一个项目,还是这么个问题……..

第二天………故事再继续
++++++++++++++++++++++++++++++++++++++++++++++++++
到底为什么呢?

好,第一反应当然是干掉它!所以Tomcat一启动,就直接读那个项目的文件了,所以总是报错找不到blog_action(很久很久之前写的小项目)。所以程序还是对的,要相信报错!按照人家报错信息去寻找。

解决办法:果断干掉这些干扰文件,重新部署,搞定!这样项目部署到了wtpwebapps目录下,和webapps同级。那么wtpwebapps和webapps什么关系?

网上这么说的:

分析:那么为什么会在webapps==>ROOT ==>下面会有classes这些东东?和配置文件呢?我查了下现在这个p2p项目,发现服务已启动,部署到了wtpwebapps下面:
D:\Program Files\apache-tomcat-8.5.24\wtpwebapps\p2pFront2\WEB-INF\classes
这个classes下面有我所有配置文件和我的代码,也就是编译后的东东。这样Tomcat顺利启动。
毫无疑问,项目一启动,首先去加载web.xml文件,因为这个web.xml才是本项目文件,然后依次加载各种配置文件。
那么:
wtpwebapps 和webapps什么关系?

(1)webapps : tomcat默认部署路径

(2)wtpwebapps : eclipse默认部署路径
查看下本项目的server.xml ;发现自动配置如下:

相比之前项目,多了一个source
也就是说项目默认部署到了Eclipse的默认路径,有什么影响呢?我们知道项目要部署到tomcat的webapps下面和Root同级别,才代表可以访问;后者直接放到Root里面,就不用输入项目名,直接可以访问。

现在的项目,也是可以访问的,前端测试成功!但是问题是,项目只有部署到Tomcat的webapps下面,才觉得舒服,对不对?
如何更改项目部署位置呢?

解决方案:

修改为了使项目默认部署到tomcat安装目录下的webapps中,show view—>servers—>找到需要修改的tomcat—>右击

①停止eclipse内的Tomcat服务器(stop)
②删除该容器中部署的项目(add and remove)
③清除该容器相关数据(clean)
④打开tomcat的修改界面(open)
⑤找到servers location,选择第二个(User tomcat Installation)
⑥修改deploy path为webapps
⑦保存关闭

①②③必须操作,否则下面的步骤会被置灰,无法操作。(感谢优快云网友!)

这里写图片描述

去tomcat目录下查看一下即可。搞定!

最后:还可能出现一些小问题:

1.java.lang.ClassNotFoundException: org.apache.taglibs.standard.tlv.JstlCoreTLV
明显缺少jstl包 把包放到Tomcat下面的lib即可;

2.el表达式不起作用?
el表达式是不用导包的,jsp默认就认识。但是因为有时候版本问题,或者编译工具问题,比如idea,
el表达式写上去,就这么显示${user.userId};没法 取值:
解决办法:

    1.方案一 
    一是在jsp页面的page指令中指定 isELIgnored属性为false,如下: 
    <%@page isELIgnored=”false” %> 
    重启tomcat运行效果如下: 


    2.方案二 
    在web.xml文件中修改其版本号和其约束,如下:因为Maven新建的web.xml我的默认是没有这个头部信息的。

     <web-app version="2.5"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" >
    重启tomcat运行的时候会遇到一点小问题,那就是jsp页面中的el表达式无法显示取值,解决办法是清空项目的编译文件。菜单栏选择project——>clean——>选择要清除的项目,然后点击ok,重启一下tomcat刷新一下页面即可。

总结:


1.处理Bug要有耐心;并不是说要一直埋头苦想,而是要反复去处理;可以间隔性处理。解决问题是要花时间的,花精力的,也要好的状态和心境;

2.增强灵活性。可以转换角度处理,不要老盯着一个地方;

3.实在不行,就颠覆性处理。比如新启一个项目;新建一个页面等等;

4.当然别忘记探讨和求助。


好了,晚安~@@所有

### 解决方案 在处理 `Error creating bean with name 'serverEndpointExporter'` 错误时,通常是因为依赖项未能正确初始化或者配置文件存在问题。具体来说,在尝试实例化 `JedisConnectionFactory` 时抛出了 `NoClassDefFoundError` 异常[^1]。 #### 可能的原因分析: - **缺少必要的库**:如果项目中使用了 Redis 并且遇到了 `NoClassDefFoundError: redis/clients/util/Pool` 的错误,则表明可能缺失了一些 JAR 文件或版本不兼容。 - **配置问题**:检查应用程序属性文件中的 Redis 配置是否正确无误,比如主机地址、端口号等参数设置不当也会引发此类问题。 针对上述情况可以采取如下措施来解决问题: 1. 确认 Maven 或 Gradle 构建工具下的 POM.xml 或 build.gradle 中含了最新的 Spring Data Redis 和 Jedis 客户端依赖,并确保这些能够成功下载并编译进入项目的 classpath 中。 2. 如果已经确认所有必需的 jar 已经存在但仍报错,请清理本地仓库缓存重新构建工程;另外也可以尝试升级至更高版本的 spring-boot-starter-data-redis 来获得更好的支持和修复已知 bug。 3. 对于配置方面的问题,建议仔细核对 application.properties 或者 yaml 格式的配置文档里关于 Redis 连接池的相关设定是否有误,特别是对于某些特定环境变量可能导致默认值失效的情况更需留意。 4. 若以上方法均无法奏效,考虑查看日志输出寻找更多线索,有时候其他 Bean 初始化失败可能会间接影响到当前这个 Bean 的创建过程,因此全面排查整个启动流程有助于定位真正根源所在。 ```xml <!-- Example of adding dependency in pom.xml --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> </dependency> ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值