how2j.cn

下载区
文件名 文件大小
ssm.rar 10m

解压rar如果失败,请用5.21版本或者更高版本的winrar

点击下载 winrar5.21

工具版本兼容问题
本知识点讲解如何在SSM中配置数据库连接池。 连接池的效果要大量测试才能够看得出效果,本知识点主要是为了将来如果你要修改成连接池的时候,复制粘贴方便~


步骤 1 : 先运行,看到效果,再学习   
步骤 2 : 模仿和排错   
步骤 3 : 基于分页进行   
步骤 4 : 修改applicationContext.xml   
步骤 5 : 测试   

步骤 1 :

先运行,看到效果,再学习

edit
老规矩,先下载右上角的可运行项目,配置运行起来,确认可用之后,再学习做了哪些步骤以达到这样的效果。
在确保可运行项目能够正确无误地运行之后,再严格照着教程的步骤,对代码模仿一遍。
模仿过程难免代码有出入,导致无法得到期望的运行结果,此时此刻通过比较正确答案 ( 可运行项目 ) 和自己的代码,来定位问题所在。
采用这种方式,学习有效果,排错有效率,可以较为明显地提升学习速度,跨过学习路上的各个槛。

推荐使用diffmerge软件,进行文件夹比较。把你自己做的项目文件夹,和我的可运行项目文件夹进行比较。
这个软件很牛逼的,可以知道文件夹里哪两个文件不对,并且很明显地标记出来
这里提供了绿色安装和使用教程:diffmerge 下载和使用教程
步骤 3 :

基于分页进行

edit
本知识点,基于分页进行。
步骤 4 :

修改applicationContext.xml

edit
注释掉52-66行的原有datasource,新增Druid连接池
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <context:annotation-config /> <context:component-scan base-package="com.how2java.service" /> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> <!-- 基本属性 url、user、password --> <property name="url" value="jdbc:mysql://localhost:3306/how2java?characterEncoding=UTF-8" /> <property name="username" value="root" /> <property name="password" value="admin" /> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <!-- 配置初始化大小、最小、最大 --> <property name="initialSize" value="3" /> <property name="minIdle" value="3" /> <property name="maxActive" value="20" /> <!-- 配置获取连接等待超时的时间 --> <property name="maxWait" value="60000" /> <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 --> <property name="timeBetweenEvictionRunsMillis" value="60000" /> <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 --> <property name="minEvictableIdleTimeMillis" value="300000" /> <property name="validationQuery" value="SELECT 1" /> <property name="testWhileIdle" value="true" /> <property name="testOnBorrow" value="false" /> <property name="testOnReturn" value="false" /> <!-- 打开PSCache,并且指定每个连接上PSCache的大小 --> <property name="poolPreparedStatements" value="true" /> <property name="maxPoolPreparedStatementPerConnectionSize" value="20" /> </bean> <!-- <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> --> <!-- <property name="driverClassName"> --> <!-- <value>com.mysql.jdbc.Driver</value> --> <!-- </property> --> <!-- <property name="url"> --> <!-- <value>jdbc:mysql://localhost:3306/how2java?characterEncoding=UTF-8</value> --> <!-- </property> --> <!-- <property name="username"> --> <!-- <value>root</value> --> <!-- </property> --> <!-- <property name="password"> --> <!-- <value>admin</value> --> <!-- </property> --> <!-- </bean> --> <bean id="sqlSession" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="typeAliasesPackage" value="com.how2java.pojo" /> <property name="dataSource" ref="dataSource"/> <property name="mapperLocations" value="classpath:com/how2java/mapper/*.xml"/> </bean> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.how2java.mapper"/> </bean> </beans>
访问页面看到如图所示效果

http://127.0.0.1:8080/ssm/listCategory


连接池要大量测试才能够看得出效果,这个测试仅仅表示可以像以前一样正常工作。

本知识点主要是为了将来如果你要修改成c3p0的时候,复制粘贴方便~
测试


HOW2J公众号,关注后实时获知最新的教程和优惠活动,谢谢。


问答区域    
2019-12-07 我是使用的是另一种连接池,站长这个连接池会报这个错误
阿龙_




<!-- JNDI获取数据源(使用dbcp连接池) --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" scope="singleton"> 这是我使用的连接池 bean

							
十二月 07, 2019 2:18:10 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Server.服务器版本:        Apache Tomcat/9.0.26
十二月 07, 2019 2:18:10 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: 服务器构建:          Sep 16 2019 15:51:39 UTC
十二月 07, 2019 2:18:10 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Server version number: 9.0.26.0
十二月 07, 2019 2:18:10 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: OS Name:               Windows 10
十二月 07, 2019 2:18:10 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: OS.版本:            10.0
十二月 07, 2019 2:18:10 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: 架构:          amd64
十二月 07, 2019 2:18:10 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Java 环境变量:             D:\java\jdk8
十二月 07, 2019 2:18:10 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: JVM 版本:           1.8.0_191-b12
十二月 07, 2019 2:18:10 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: JVM.供应商:            Oracle Corporation
十二月 07, 2019 2:18:10 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: CATALINA_BASE:         D:\tomcat\apache-tomcat-9.0.26
十二月 07, 2019 2:18:10 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: CATALINA_HOME:         D:\tomcat\apache-tomcat-9.0.26
十二月 07, 2019 2:18:10 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dcatalina.base=D:\tomcat\apache-tomcat-9.0.26
十二月 07, 2019 2:18:10 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dcatalina.home=D:\tomcat\apache-tomcat-9.0.26
十二月 07, 2019 2:18:10 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dwtp.deploy=D:\tomcat\apache-tomcat-9.0.26\webapps
十二月 07, 2019 2:18:10 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Djava.endorsed.dirs=D:\tomcat\apache-tomcat-9.0.26\endorsed
十二月 07, 2019 2:18:10 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dfile.encoding=UTF-8
十二月 07, 2019 2:18:10 下午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent
信息: Loaded APR based Apache Tomcat Native library [1.2.23] using APR version [1.7.0].
十二月 07, 2019 2:18:10 下午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent
信息: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
十二月 07, 2019 2:18:10 下午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent
信息: APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
十二月 07, 2019 2:18:10 下午 org.apache.catalina.core.AprLifecycleListener initializeSSL
信息: OpenSSL successfully initialized [OpenSSL 1.1.1c  28 May 2019]
十二月 07, 2019 2:18:10 下午 org.apache.coyote.AbstractProtocol init
信息: 初始化协议处理器 ["http-nio-8080"]
十二月 07, 2019 2:18:11 下午 org.apache.coyote.AbstractProtocol init
信息: 初始化协议处理器 ["ajp-nio-8009"]
十二月 07, 2019 2:18:11 下午 org.apache.catalina.startup.Catalina load
信息: 服务器在[1,118]毫秒内初始化
十二月 07, 2019 2:18:11 下午 org.apache.catalina.core.StandardService startInternal
信息: Starting service [Catalina]
十二月 07, 2019 2:18:11 下午 org.apache.catalina.core.StandardEngine startInternal
信息: Starting Servlet engine: [Apache Tomcat/9.0.26]
十二月 07, 2019 2:18:12 下午 org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory getObjectInstance
警告: Name = mysql Property maxActive is not used in DBCP2, use maxTotal instead. maxTotal default value is 8. You have set value of "100" for "maxActive" property, which is being ignored.
十二月 07, 2019 2:18:12 下午 org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory getObjectInstance
警告: Name = mysql Property maxWait is not used in DBCP2 , use maxWaitMillis instead. maxWaitMillis default value is -1. You have set value of "10000" for "maxWait" property, which is being ignored.
十二月 07, 2019 2:18:12 下午 org.apache.catalina.core.ApplicationContext log
信息: No Spring WebApplicationInitializer types detected on classpath
十二月 07, 2019 2:18:12 下午 org.apache.jasper.servlet.TldScanner scanJars
信息: 至少有一个JAR被扫描用于TLD但尚未包含TLD。 为此记录器启用调试日志记录,以获取已扫描但未在其中找到TLD的完整JAR列表。 在扫描期间跳过不需要的JAR可以缩短启动时间和JSP编译时间。
十二月 07, 2019 2:18:12 下午 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring root WebApplicationContext
ERROR [main] - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSession' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [D:\tomcat\apache-tomcat-9.0.26\webapps\ssm\WEB-INF\classes\com\how2java\mapper\Category.xml]'; nested exception is java.lang.RuntimeException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class . Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'Category'.  Cause: java.lang.ClassNotFoundException: Cannot find class: Category
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1514)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:618)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:938)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:410)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4685)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5146)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
	at java.util.concurrent.AbstractExecutorService.submit(Unknown Source)
	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
	at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:841)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
	at java.util.concurrent.AbstractExecutorService.submit(Unknown Source)
	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
	at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.core.StandardService.startInternal(StandardService.java:421)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:932)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:633)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:344)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:475)
Caused by: org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [D:\tomcat\apache-tomcat-9.0.26\webapps\ssm\WEB-INF\classes\com\how2java\mapper\Category.xml]'; nested exception is java.lang.RuntimeException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class . Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'Category'.  Cause: java.lang.ClassNotFoundException: Cannot find class: Category
	at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:468)
	at org.mybatis.spring.SqlSessionFactoryBean.afterPropertiesSet(SqlSessionFactoryBean.java:343)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1573)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1511)
	... 42 more
Caused by: java.lang.RuntimeException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class . Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'Category'.  Cause: java.lang.ClassNotFoundException: Cannot find class: Category
	at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:113)
	at org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:88)
	at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:466)
	... 45 more
Caused by: org.apache.ibatis.builder.BuilderException: Error resolving class . Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'Category'.  Cause: java.lang.ClassNotFoundException: Cannot find class: Category
	at org.apache.ibatis.builder.BaseBuilder.resolveClass(BaseBuilder.java:94)
	at org.apache.ibatis.builder.xml.XMLStatementBuilder.parseStatementNode(XMLStatementBuilder.java:79)
	at org.apache.ibatis.builder.xml.XMLMapperBuilder.buildStatementFromContext(XMLMapperBuilder.java:128)
	at org.apache.ibatis.builder.xml.XMLMapperBuilder.buildStatementFromContext(XMLMapperBuilder.java:121)
	at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:111)
	... 47 more
Caused by: org.apache.ibatis.type.TypeException: Could not resolve type alias 'Category'.  Cause: java.lang.ClassNotFoundException: Cannot find class: Category
	at org.apache.ibatis.type.TypeAliasRegistry.resolveAlias(TypeAliasRegistry.java:109)
	at org.apache.ibatis.builder.BaseBuilder.resolveAlias(BaseBuilder.java:115)
	at org.apache.ibatis.builder.BaseBuilder.resolveClass(BaseBuilder.java:92)
	... 51 more
Caused by: java.lang.ClassNotFoundException: Cannot find class: Category
	at org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:188)
	at org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:87)
	at org.apache.ibatis.io.Resources.classForName(Resources.java:250)
	at org.apache.ibatis.type.TypeAliasRegistry.resolveAlias(TypeAliasRegistry.java:105)
	... 53 more
十二月 07, 2019 2:18:13 下午 org.apache.catalina.core.StandardContext listenerStart
严重: 异常将上下文初始化事件发送到类的侦听器实例.[org.springframework.web.context.ContextLoaderListener]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSession' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [D:\tomcat\apache-tomcat-9.0.26\webapps\ssm\WEB-INF\classes\com\how2java\mapper\Category.xml]'; nested exception is java.lang.RuntimeException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class . Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'Category'.  Cause: java.lang.ClassNotFoundException: Cannot find class: Category
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1514)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:618)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:938)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:410)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4685)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5146)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
	at java.util.concurrent.AbstractExecutorService.submit(Unknown Source)
	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
	at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:841)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
	at java.util.concurrent.AbstractExecutorService.submit(Unknown Source)
	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
	at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.core.StandardService.startInternal(StandardService.java:421)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:932)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:633)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:344)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:475)
Caused by: org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [D:\tomcat\apache-tomcat-9.0.26\webapps\ssm\WEB-INF\classes\com\how2java\mapper\Category.xml]'; nested exception is java.lang.RuntimeException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class . Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'Category'.  Cause: java.lang.ClassNotFoundException: Cannot find class: Category
	at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:468)
	at org.mybatis.spring.SqlSessionFactoryBean.afterPropertiesSet(SqlSessionFactoryBean.java:343)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1573)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1511)
	... 42 more
Caused by: java.lang.RuntimeException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class . Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'Category'.  Cause: java.lang.ClassNotFoundException: Cannot find class: Category
	at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:113)
	at org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:88)
	at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:466)
	... 45 more
Caused by: org.apache.ibatis.builder.BuilderException: Error resolving class . Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'Category'.  Cause: java.lang.ClassNotFoundException: Cannot find class: Category
	at org.apache.ibatis.builder.BaseBuilder.resolveClass(BaseBuilder.java:94)
	at org.apache.ibatis.builder.xml.XMLStatementBuilder.parseStatementNode(XMLStatementBuilder.java:79)
	at org.apache.ibatis.builder.xml.XMLMapperBuilder.buildStatementFromContext(XMLMapperBuilder.java:128)
	at org.apache.ibatis.builder.xml.XMLMapperBuilder.buildStatementFromContext(XMLMapperBuilder.java:121)
	at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:111)
	... 47 more
Caused by: org.apache.ibatis.type.TypeException: Could not resolve type alias 'Category'.  Cause: java.lang.ClassNotFoundException: Cannot find class: Category
	at org.apache.ibatis.type.TypeAliasRegistry.resolveAlias(TypeAliasRegistry.java:109)
	at org.apache.ibatis.builder.BaseBuilder.resolveAlias(BaseBuilder.java:115)
	at org.apache.ibatis.builder.BaseBuilder.resolveClass(BaseBuilder.java:92)
	... 51 more
Caused by: java.lang.ClassNotFoundException: Cannot find class: Category
	at org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:188)
	at org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:87)
	at org.apache.ibatis.io.Resources.classForName(Resources.java:250)
	at org.apache.ibatis.type.TypeAliasRegistry.resolveAlias(TypeAliasRegistry.java:105)
	... 53 more

十二月 07, 2019 2:18:13 下午 org.apache.catalina.core.StandardContext startInternal
严重: One or more listeners failed to start. Full details will be found in the appropriate container log file
十二月 07, 2019 2:18:13 下午 org.apache.catalina.core.StandardContext startInternal
严重: Context [/ssm] startup failed due to previous errors
十二月 07, 2019 2:18:13 下午 org.apache.catalina.core.ApplicationContext log
信息: Closing Spring root WebApplicationContext
十二月 07, 2019 2:18:13 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc
警告: Web应用程序 [ssm] 注册了JDBC驱动程序 [com.alibaba.druid.proxy.DruidDriver],但在Web应用程序停止时无法注销它。 为防止内存泄漏,JDBC驱动程序已被强制取消注册。
十二月 07, 2019 2:18:13 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc
警告: Web应用程序 [ssm] 注册了JDBC驱动程序 [com.mysql.jdbc.Driver],但在Web应用程序停止时无法注销它。 为防止内存泄漏,JDBC驱动程序已被强制取消注册。
十二月 07, 2019 2:18:13 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
警告: The web application [ssm] appears to have started a thread named [MySQL Statement Cancellation Timer] 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.Object.wait(Unknown Source)
 java.util.TimerThread.mainLoop(Unknown Source)
 java.util.TimerThread.run(Unknown Source)
十二月 07, 2019 2:18:13 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: 把web 应用程序部署到目录 [D:\tomcat\apache-tomcat-9.0.26\webapps\ROOT]
十二月 07, 2019 2:18:14 下午 org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory getObjectInstance
警告: Name = mysql Property maxActive is not used in DBCP2, use maxTotal instead. maxTotal default value is 8. You have set value of "100" for "maxActive" property, which is being ignored.
十二月 07, 2019 2:18:14 下午 org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory getObjectInstance
警告: Name = mysql Property maxWait is not used in DBCP2 , use maxWaitMillis instead. maxWaitMillis default value is -1. You have set value of "10000" for "maxWait" property, which is being ignored.
十二月 07, 2019 2:18:14 下午 org.apache.jasper.servlet.TldScanner scanJars
信息: 至少有一个JAR被扫描用于TLD但尚未包含TLD。 为此记录器启用调试日志记录,以获取已扫描但未在其中找到TLD的完整JAR列表。 在扫描期间跳过不需要的JAR可以缩短启动时间和JSP编译时间。
十二月 07, 2019 2:18:14 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deployment of web application directory [D:\tomcat\apache-tomcat-9.0.26\webapps\ROOT] has finished in [108] ms
十二月 07, 2019 2:18:14 下午 org.apache.coyote.AbstractProtocol start
信息: 开始协议处理句柄["http-nio-8080"]
十二月 07, 2019 2:18:14 下午 org.apache.coyote.AbstractProtocol start
信息: 开始协议处理句柄["ajp-nio-8009"]
十二月 07, 2019 2:18:14 下午 org.apache.catalina.startup.Catalina start
信息: Server startup in [2,914] milliseconds


2 个答案

闷油瓶
答案时间:2020-01-10
换高版本druid解决了。。。
<druid.version>1.1.13</druid.version>

阿龙_
答案时间:2019-12-07
如遇我一样的问题,请重启电脑后测试!一定要相信java玄学



回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
答案 或者 代码至少填写一项, 如果是自己有问题,请重新提问,否则站长有可能看不到





2019-09-11 没用连接池时连接正常,换了连接池连接就出错,求大神解答
MrYang123




网上说jar包版本不兼容MySQL,但是没有还连接池时还能连接。异常代码如下: ERROR [localhost-startStop-1] - init datasource error, url: jdbc:mysql://localhost:3306/how2java?characterEncoding=UTF-8 java.sql.SQLException: Unknown system variable 'tx_isolation' at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)

							
ERROR [localhost-startStop-1] - init datasource error, url: jdbc:mysql://localhost:3306/how2java?characterEncoding=UTF-8
java.sql.SQLException: Unknown system variable 'tx_isolation'
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)


3 个答案

Hiyx
答案时间:2022-01-13
mysql 8.0+版本驱动包和driverClassName和之前的版本都是不一样的,url可能需要配置其他信息,比如时区。建议先确定数据库可以正常连接再看整体效果

123liang
答案时间:2020-10-28
我的问题是一样的,我本地的数据库版本是8.0.17,站长给的包里mysql-connector-java是5.*,把这个把换成mysql-connector-java-8.0.17*, 就解决里druid包的问题(druid包不用换)

toBeOrdinary
答案时间:2019-11-16
一样的情况,我的是MySQL数据库版本问题, 将MySQL版本从8.0,15降到了5.5 得以解决(也可以提高druid版本,当然只是一种思路 ) //所以插件版本跟着站长走是多么重要。。。
报错内容:registered the JDBC driver [com.alibaba.druid.proxy.DruidDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.



回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
答案 或者 代码至少填写一项, 如果是自己有问题,请重新提问,否则站长有可能看不到





2019-07-26 为什么我换成连接池好后 就一直报错 换成之前的就正常运行
2019-07-14 关于eclipse中写xml文件时属性值为斜体的建议
2018-02-25 开发中常用哪种连接池呢?和spirngboot结合?


提问太多,页面渲染太慢,为了加快渲染速度,本页最多只显示几条提问。还有 1 条以前的提问,请 点击查看

提问之前请登陆
提问已经提交成功,正在审核。 请于 我的提问 处查看提问记录,谢谢
关于 JAVA 框架-SSM-连接池 的提问

尽量提供截图代码异常信息,有助于分析和解决问题。 也可进本站QQ群交流: 578362961
提问尽量提供完整的代码,环境描述,越是有利于问题的重现,您的问题越能更快得到解答。
对教程中代码有疑问,请提供是哪个步骤,哪一行有疑问,这样便于快速定位问题,提高问题得到解答的速度
在已经存在的几千个提问里,有相当大的比例,是因为使用了和站长不同版本的开发环境导致的,比如 jdk, eclpise, idea, mysql,tomcat 等等软件的版本不一致。
请使用和站长一样的版本,可以节约自己大量的学习时间。 站长把教学中用的软件版本整理了,都统一放在了这里, 方便大家下载: https://how2j.cn/k/helloworld/helloworld-version/1718.html

上传截图