BasicDataSource provoquant java.util.ConcurrentModificationException dans WebSphere

BasicDataSource provoquant java.util.ConcurrentModificationException dans WebSphere

Problème

Avec Spring, déclare la source de données comme «org.apache.commons.dbcp.BasicDataSource». Une fois déployé sur WebSphere, tout fonctionne parfaitement.

Fichier: spring-datasource.xml




    
       
           classpath:config/database/database.properties
       
    

    
        
    
    
    
    

Cependant, lorsque vous redémarrez l'application Web dans WebSphere, elle obtient l'exception suivante:

org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'dataSource' defined in class path resource
[config/database/spring/spring-datasource.xml]: Instantiation of bean failed;
......
Caused by: java.lang.ExceptionInInitializerError
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:222)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    ... 114 more
Caused by: java.util.ConcurrentModificationException
    at java.util.AbstractList$SimpleListIterator.next(Unknown Source)
    at java.sql.DriverManager.getDrivers(Unknown Source)
    at org.apache.commons.dbcp.BasicDataSource.(BasicDataSource.java:57)
    at java.lang.J9VMInternals.initializeImpl(Native Method)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
    ... 121 more

On dirait que la source de données (BasicDataSource) est à l'origine de «java.util.ConcurrentModificationException».

Solution

Vous devez utiliser la source de données WebSphere et non «org.apache.commons.dbcp.BasicDataSource». Pour résoudre ce problème, enregistrez simplement une source de données WebSphere et mettez un nom jndi comme «jdbc/anythingDS». Au printemps, déclare la source de données jdni comme ceci:

Fichier: spring-datasource.xml




    
        
        
        
        
    

Dans le développement WebSphere, vous devez suivre la façon de faire de WebSphere.