When you turn on and off tomcat`a sometimes this error occurs

24-Aug-2016 21: 58: 01.947 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesJdbc The web application [ROOT] registered JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. The driver has been forcibly unregistered.

24-Aug-2016 21: 58: 01.948 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [ROOT] seems 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(ReferenceQueue.java:143) com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:43) 

In the tomcat8/lib folder, the jdbc connector was thrown up, it did not help. I use 5.1.38

UPDATE: For example, as I get the user, I will give snippets of code

Service

 @Transactional @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { User user = userDao.getByUsername(username); 

DAO

 @Override public User getByUsername(String username) { Criteria criteria = getSession().createCriteria(User.class); criteria.add(Restrictions.eq("username", username)); return (User)criteria.uniqueResult(); } 

According to the idea I should not close getSession Hibernate

xml

 <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="packagesToScan"> <list> <value>ru.erp.models</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.hbm2ddl.auto">update</prop> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">false</prop> <prop key="hibernate.connection.charSet">UTF-8</prop> <prop key="hibernate.enable_lazy_load_no_trans">true</prop> </props> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"/> </bean> <bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close"> <property name="driverClassName" value="com.mysql.jdbc.Driver"/> <property name="url" value="${db.url}"/> <property name="username" value="${db.username}"/> <property name="password" value="${db.password}"/> <property name="initialSize" value="10" /> <property name="maxActive" value="500" /> <property name="maxIdle" value="40" /> <property name="minIdle" value="1" /> <property name="maxWait" value="5000" /> <property name="removeAbandoned" value="true" /> <property name="validationQuery" value="SELECT 1"/> <property name="testOnBorrow" value="true"/> </bean> 
  • rather, for all of you somewhere you don’t close the connection, therefore, the three-way-klinap continues to hang in memory, or it’s a bug in the driver (which is unlikely) you can try using another version or a version from another developer (if any) - jmu

1 answer 1

After mysql-connector-java thrown into the lib folder, you need to remove it from the project. If you use maven, then you need to specify in runtime in scope :

 <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>...</version> <scope>runtime</scope> </dependency> 
  • I will try to do this too, that is, can I specify a runtime in the mavena and not remove the principle from the project? - Kleimosc
  • one
    If you specify runtime, then maven will not pack the library into a war file. And when you start the application tomcat not finding it inside the project will look for it in the lib folder. - Nick
  • Well, even though it even beat me in ide. I think this is not a problem. Well, in general, I hope to get rid of the error by changing the datasource - Kleimosc
  • You have replaced the connection pool (several connections are created in advance and when you call getConnection() “by quick”, an already open connection is returned) to the source, which will open a new connection every time. - Nick